home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 042a / swagdef.zip / EGAVGA.SWG < prev    next >
Text File  |  1993-05-28  |  131KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00048         EGA/VGA ROUTINES                                                  1      05-28-9313:39ALL                      SWAG SUPPORT TEAM        BESTFADE.PAS             IMPORT              12          {πREYNIR STEFANSSONππ     Here is yet another fade-in routine. This one does a proportional fadeπof all colours.π}ππProgram FadeDemo;ππUsesπ  Crt;ππConstπ  PelAddrRgR  = $3C7;π  PelAddrRgW  = $3C8;π  PelDataReg  = $3C9;ππTypeπ  rgb = Recordπ    r, g, b : Byte;π  end;ππVarπ  i   : Integer;π  ch  : Char;π  col : Array[0..63] of rgb;ππProcedure GetCol(C : Byte; Var R, G, B : Byte);πbeginπ  Port[PelAddrRgR] := C;π  R := Port[PelDataReg];π  G := Port[PelDataReg];π  B := Port[PelDataReg];πend;ππProcedure SetCol(C, R, G, B : Byte);πbeginπ  Port[PelAddrRgW] := C;π  Port[PelDataReg] := R;π  Port[PelDataReg] := G;π  Port[PelDataReg] := B;πend;ππProcedure SetInten(b : Byte);πVarπ  i  : Integer;π  fr,π  fg,π  fb : Byte;πbeginπ  For i := 0 to 63 DOπ  beginπ    fr := col[i].r * b div 63;π    fg := col[i].g * b div 63;π    fb := col[i].b * b div 63;π    SetCol(i, fr, fg, fb);π  end;πend;ππbeginπ  TextMode(LastMode);π  For i := 0 to 63 DOπ    GetCol(i, col[i].r, col[i].g, col[i].b);π  For i := 1 to 15 DOπ  beginπ    TextAttr := i;π    WriteLn('Foreground colour = ', i : 2);π  end;π  ch := ReadKey;π  For i := 63 DOWNTO 0 DOπ  beginπ    SetInten(i);π    Delay(20);π  end;π  GotoXY(1, 1);π  For i := 15 DOWNTO 1 DOπ  beginπ    TextAttr := i;π    WriteLn('Foreground colour = ', i : 2);π  end;ππ  For i := 0 to 63 DOπ  beginπ    SetInten(i);π    Delay(20);π  end;π  ch := ReadKey;π  TextMode(LastMode);πend.π  2      05-28-9313:39ALL                      SWAG SUPPORT TEAM        BGIEXE2.PAS              IMPORT              7           {π>How do I compile a Graphic Program With the Graph included.ππI think what you'd like to be included in your EXE File are the BGI drivers ;πhere is a sample code to include the EGAVGA.BGI driver in your EXE :π}ππUnit EgaVga;ππInterfaceππUsesπ  Graph;ππImplementationππ{$L EgaVga}πProcedure DriverEgaVga; External;ππbeginπ  If RegisterBGIDriver(@DriverEgaVga)<0 Thenπ    Halt(1);πend.ππ{πWhat you need to do is just include the Unit in your 'Uses' statement.πWell, prior to do this, you'll need to enter the following command atπthe Dos prompt :ππBinObj EGAVGA.BGI EGAVGA.Obj DriverEgaVgaππYou cand do the same For the other .BGI Files, and even For the .CHR (font)πFiles -just replacing RegisterBGIDriver With RegisterBGIFont, I think.π}                             3      05-28-9313:39ALL                      SWAG SUPPORT TEAM        BITFONTS.PAS             IMPORT              130         {π>I need to Write some Pascal code For a PC that will allow Text modeπ>fonts to be changed (at least on PC's With VGA adapters).ππ>Prof. Salmi's FAQ lists a book by Porter and Floyd, "Stretchingπ>Turbo Pascal", as having the relevant information, but my localπ>bookstore claims this is out of print.ππYou could try borrowing the book from the library.  For instance oursπwill search For books; I rarely buy books.  STP:v5.5 was an exception.πHere is code (substantially based on Porter and Floyds' code) writtenπfor version 5.x .  Actually, aside from this stuff, the book wasn't asπgood as I thought it would be.  I believe Ken Porter died and parts ofπthe book seem missing.  This code, For instance, isn't well documentedπin the book (althought I think its clear how to use it from theseπPrograms).ππYou know, after playing With this code I thought I knew it all :DπIt turns out that there is a lot more you can do.  For instance, theπintensity bit can be used as an extra Character bit to allowπ512-Character fonts.  I have an aging PC Magazine article (that Iπhaven't gotten around to playing with) that has some Asm code For theπEGA.  (I'm hoping the same code will work For the VGA).π}π{--[rounded.pas]--}ππProgramπ  Rounded;πUsesπ  Crt, BitFonts;ππTypeπ  matrix = Array[0..15] of Byte;ππConstπ  URC : matrix = ($00,$00,$00,$00,$00,$00,$00,$C0,$70,$30,$18,$18,$18,$18,$18,$18);π  LLC : matrix = ($18,$18,$18,$18,$0C,$0E,$03,$00,$00,$00,$00,$00,$00,$00,$00,$00);π  LRC : matrix = ($18,$18,$18,$18,$30,$70,$C0,$00,$00,$00,$00,$00,$00,$00,$00,$00);π  ULC : matrix = ($00,$00,$00,$00,$00,$00,$00,$03,$0E,$0C,$18,$18,$18,$18,$18,$18);π{  ULC : matrix = ($00,$00,$00,$00,$00,$03,$0E,$19,$33,$36,$36,$36,$36,$36,$36,$36);}πVarπ  index,b      : Word;π  package      : fontPackagePtr;π  FontFile     : File of FontPackage;π  EntryFont    : ROMfont;ππ  Procedure TextBox( left, top, right, bottom, style : Integer );π    Constπ      bord : Array[1..2,0..5] of Char = ( ( #196,#179,#218,#191,#217,#192 ),π                                          ( #205,#186,#201,#187,#188,#200 ));π    Var P:Integer;ππ    beginπ      if Style = 0 then Exit; { what the fuck is this For ? }ππ      { verify coordinates are in ( NW,SE ) corner }π      if left > right thenπ        beginπ          p := left; left := right; right := p;π        end;π      if bottom < top thenπ        beginπ          p := top; top := bottom; bottom := p;π        end;ππ      { draw top }π      GotoXY( left,top );π      Write( bord[style,2] );π      For p := left+1 to right-1 doπ        Write( bord[style,0]);π      Write( bord[style,3] );ππ      { draw bottomm }π      GotoXY( left,bottom );π      Write( bord[style,5]);π      For p := left+1 to right-1 doπ        Write( bord[style,0]);π      Write( bord[style,4]);ππ      { draw sides }π      For p := top+1 to bottom-1 doπ        beginπ          GotoXY( left,p );π          Write( bord[style,1] );π          GotoXY( right,p );π          Write( bord[style,1] );π        end;π    end; { Procedure TextBox }ππ  Procedure replace( ASCII:Word; newChar:matrix );π    Var offset,b:Word;π    beginπ      offset := ASCII * VDA.points;π      For b := 0 to VDA.points-1 doπ        package^.ch[offset+b] := newChar[b];π    end;ππbeginπ  if not isEGA thenπ    beginπ      Writeln( 'You can only run this Program on EGA or VGA systems' );π      halt( 1 );π    end;π  {- fetch copy of entry font -}π  EntryFont := CurrentFont;π  Package := FetchHardwareFont( CurrentFont );ππ  {- replace the corner Characters -}π  replace( 191,URC );π  replace( 192,LLC );π  replace( 217,LRC );π  replace( 218,ULC );ππ  {- load and active user-modified font -}π  Sound( 1000 );π  LoadUserFont( package );π  NoSound;ππ  {- Draw a Text box -}π  ClrScr;π{  CursorOff; }π  TextBox( 20,5,60,20,1 );π  GotoXY( 33,12 ); Write( 'rounded corners' );π{  WaitForKey;}π  readln;ππ  {- save user-modified font to File -}π  assign( FontFile, 'HELLO' );π  reWrite( FontFile );π  Write( FontFile,Package^ );π  close( FontFile );ππ  {- clear and quit -}π  SetHardWareFont( EntryFont );π  ClrScr;π{  CursorOn;}ππend.ππ{--[editfnt2.pas]--}ππProgram EditFont;ππUses Crt, Dos, BitFonts;ππConstπ  Block = #220;π  Esc = #27;πVarπ  c,π  Choice : Char;π  EditDone,π  Done,π  Valid  : Boolean;π  Font   : ROMfont;π  package : FontPackagePtr;π  fout : File of FontPackage;π  foutfil : String;ππFunction UpperCase( s:String ): String;π  Var i:Byte;π  beginπ    For i := 1 to length( s ) doπ      s[i] := UpCase( s[i] );π    UpperCase := s;π  end;πππFunction HexByte( b:Byte ):String;π  Const DIGIT : Array[0..15] of Char = '0123456789ABCDEF';π  beginπ    HexByte := Digit[b SHR 4] + Digit[b and $0F];π  end;πππFunction ByteBin( Var bs:String ):Byte;π  Const DIGIT : Array[0..15] of Char = '0123456789ABCDEF';π  Var i,b:Byte;π  beginπ    b := 0;π    For i := 2 to length( bs ) doπ      if bs[i] = '1' thenπ        b := b + 2 SHL (i-1);π    if bs[1] = '1' thenπ      b := b + 1;π    ByteBin := b;π  end;πππProcedure Browse( Font:ROMfont );ππ{π    arrow keys to manueverπ    Esc to acceptπ    Enter or space to toggle bitπ    C or c to clear a rowπ    alt-C or ctl-C to clear whole Charππ}π  Constπ    MapRow = ' - - - - - - - - ';π    MapTop = 7;ππ  Varπ    ASCII,π    row,π    col,π    index,π    bit   : Word;π    f     : Char_table;π    s     : String;π    error : Integer;ππ  Procedure putChar( value:Word );π    Var reg:Registers;π    beginπ      reg.AH := $0A;π      reg.AL := Byte( value );π      reg.BH := 0;π      reg.BL := LightGray;π      reg.CX := 1;π      intr( $10,reg );π      GotoXY( WhereX+1, WhereY );π    end; { proc putChar }ππ  beginπ    GetMem( Package, SizeOf( Package^ ));π    ClrScr;π    Package := FetchHardwareFont( Font );π    Repeatπ      GotoXY( 1,1 );π      Write( 'FONT: ' );π      Case Font ofπ        ROM8x8  : Writeln( '8 x 8' );π        ROM8x14 : Writeln( '8 x 14' );π        ROM8x16 : Writeln( '8 x 16' );π      end;π      Writeln;π      clreol;π      Write( 'ASCII value to examine? (or QUIT to quit) ' );π      readln( s );π      Val( s,ASCII,error );π      if error <> 0 thenπ        if UpperCase( s ) = 'QUIT' thenπ          Done := Trueπ        elseπ          ASCII := Byte( s[1] );ππ      { show the Character image }π      clreol;π      Write( '(Image For ASCII ',ASCII,' is ' );π      putChar( ASCII );π      Writeln( ')' );ππ      { display blank bitmap }π      GotoXY( 1,MapTop );π      For row := 1 to Package^.FontInfo.points doπ        Writeln( maprow );ππ      { explode the image bitmap }π      index := Package^.FontInfo.points * ASCII;π      For row := 0 to Package^.FontInfo.points-1 doπ        beginπ          For bit := 0 to 7 doπ            if (( Package^.Ch[index] SHR bit ) and 1 ) = 1 thenπ              beginπ                col := ( 8 - bit ) * 2;π                GotoXY( col,row+MapTop );π                Write( block );π              end;π          GotoXY( 20,row+MapTop );π          Write( hexByte( Package^.Ch[index] )+ 'h' );π          inc( index );π        end;πππ      { edit font }π      col := 2;π      row := MapTop;π      EditDone := False;π      index := Package^.FontInfo.points * ASCII;ππ      While ( not Done ) and ( not EditDone ) doπ        beginπ          GotoXY( col,row );π          c := ReadKey;π          if c = #0 thenπ            c := ReadKey;ππ          Case c ofππ            #03,         { wipe entire letter }π            #46 : beginπ                    index := Package^.FontInfo.points * ASCII;π                    For row := MapTop to MapTop+Package^.FontInfo.points-1 doπ                      beginπ                        Package^.Ch[index] := 0;π                        col := 2;π                        GotoXY( col,row );π                        Write( '- - - - - - -' );π                        GotoXY( 20,row );π                        Write( hexByte( Package^.Ch[index] )+ 'h' );π                        GotoXY( col,row );π                        inc( index );π                      end;π                  end;ππ            'C',         { wipe row }π            'c' : beginπ                    Package^.Ch[index] := 0;π                    col := 2;π                    GotoXY( col,row );π                    Write( '- - - - - - -' );π                    GotoXY( 20,row );π                    Write( hexByte( Package^.Ch[index] )+ 'h' );π                    GotoXY( col,row );π                  end;πππ            #27 : EditDone := True;  { esc }ππ            #72 : begin  { up }π                    if row >  MapTop thenπ                      beginπ                        dec( row );π                        dec( index );π                      end;π                  end;ππ            #80 : begin  { down }π                    if row < ( MapTop + Package^.FontInfo.points - 1 ) thenπ                      beginπ                        inc( row );π                        inc( index );π                      end;π                  end;ππ            #77 : begin  { right }π                    if col < 16 thenπ                      inc( col,2 );π                  end;ππ            #75 : begin  { left }π                    if col > 3 thenπ                      dec( col,2 );π                  end;ππ            #13,π            #10,π            ' ' : beginπ                    bit := 8 - ( col div 2 );π                    if (( Package^.Ch[index] SHR bit ) and 1 ) = 1 thenπ                      beginπ                        Package^.Ch[index] := ( Package^.Ch[index] ) ANDπ                                               ($FF xor ( 1 SHL bit ));π                        Write( '-' )π                      endπ                    elseπ                      beginπ                        Package^.Ch[index] := Package^.Ch[index] XORπ                                              ( 1 SHL bit );π                        Write( block );π                      end;ππ                    GotoXY( 20,row );π                    Write( hexByte( Package^.Ch[index] )+ 'h' );π                    GotoXY( col,row );π                  end;ππ          end; { Case }ππ          LoadUserFont( Package );ππ        end; { While }ππ    Until Done;ππ    GotoXY( 40,7 );π    Write( 'Save to disk? (Y/n) ');π    Repeatπ      c := UpCase( ReadKey );π    Until c in ['Y','N',#13];π    if c = #13 thenπ      c := 'Y';π    Write( c );ππ    if c = 'Y' thenπ      beginπ        GotoXY( 40,9 );π        ClrEol;π        Write( 'Save as: ');π        readln( foutfil );ππ(*        if fexist( foutfil ) thenπ          beginπ            GotoXY( 40,7 );π            Write( 'OverWrite File ''',foutfil,''' (y/N) ');π            Repeatπ              c := UpCase( ReadKey );π            Until c in ['Y','N',#13];π            if c = #13 thenπ              c := 'N';π            Write( c );π          end;π*)π        {$I-}π        assign( fout,foutfil ); reWrite( fout );π        Write( fout,Package^ );π        close( fout );π        {$I+}π        GotoXY( 40,11 );π        if ioResult <> 0 thenπ          Writeln( 'Write failed!' )π        elseπ          Writeln( 'Wrote font to File ''',foutfil,'''.' );π      end;πππ  end; { proc Browse }πππbeginππ  Done := False;π  { get font to view }π  Repeatπ    Valid := False;π    Repeatπ      ClrScr;π      Writeln( 'Fonts available For examination: ' );π      Writeln( '    1. 8 x 8' );π      if isEGA thenππ        Writeln( '    2. 8 x 14' );π      if isVGA thenπ        Writeln( '    3. 8 x 16' );π      Writeln;π      Write( '    Select by number (or Esc to quit) ' );π      choice := ReadKey;π      if Choice = Esc thenπ        beginπ          ClrScr;π          Exit;π        end;π      if Choice = '1' then Valid := True;π      if ( choice = '2' ) and isEGA then Valid := True;π      if ( Choice = '3' ) and isVGA then Valid := True;π    Until Valid;ππ    { fetch and display selected font }π    Case choice ofπ      '1' : Font := ROM8x8;π      '2' : Font := ROM8x14;π      '3' : Font := ROM8x16;π    end;π    Browse( font );π  Until Done;π  GotoXY( 80,25 );π  Writeln;π  Writeln( 'Thanks you For using EditFont which is based on code from' );π  Writeln( '_Stretching Turbo Pascal_ by Kent Porter and Mike Floyd.' );π  Writeln;π  Writeln( 'This Program was developed 12 Apr 92 by Alan D. Mead.' );πend.ππ{--[bitfonts.pas]--}πππUnit BitFonts;π  { support For bit-mapped Text fonts on EGA/VGA }ππInterfaceππTypeπ              { enumeration of ROM hardware fonts }π  ROMfont = ( ROM8x14, ROM8x8, ROM8x16 );ππ              { Characetr definition table }π  CharDefTable = Array[0..4095] of Byte;π  CharDefPtr   = ^CharDefTable;ππ              { For geting Text Character generators }π  Char_table = Recordπ                 points : Byte;       { Char matrix height }π                 def    : CharDefPtr; { address of table }π               end;ππ              { font format }π  FontPackage = Recordπ                  FontInfo : Char_Table;π                  ch       : CharDefTable;π                end;π  FontPackagePtr = ^FontPackage;ππ              { table maintained by video ROM BIOS at 40h : 84h }π  VideoDataArea = Recordπ                    rows   : Byte;  { Text rows on screem - 1 }π                    points : Word;    { height of Char matrix }π                    info,               { EGA/VGA status info }π                    info_3,           { EGA/VGA configuration }π                    flags  : Word;               { misc flags }π                  end;           { remainder of table ignored }ππ              { globally visible }πVarπ  VDA         : VideoDataArea Absolute $40:$84;   { equipment flags }π  isEGA,π  isVGA,π  isColor     : Boolean;π  CurrentFont : ROMfont; { default hardware font }ππProcedure GetCharGenInfo( font:ROMfont; Var table:Char_table );πProcedure SetHardWareFont( font:ROMfont );πFunction FetchHardwareFont( font:ROMfont ):FontPackagePtr;πProcedure LoadUserFont( pkg:FontPackagePtr );ππ{ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }ππImplementationππUses Dos, Crt {, TextScrn} ;ππVar reg:Registers;ππProcedure GetCharGenInfo( font:ROMfont; Var table:Char_table );π  beginπ    if isEGA thenπ      beginπ        reg.AH := $11;π        reg.AL := $30;π        Case font ofπ          ROM8x8  : reg.BH := 3;π          ROM8x14 : reg.BH := 2;π          ROM8x16 : reg.BH := 6;π        end;π        intr( $10,reg );π        table.def := ptr( reg.ES,reg.BP ); { address of definition table }π        Case font ofπ          ROM8x8  : table.points :=  8;π          ROM8x14 : table.points := 14;π          ROM8x16 : table.points := 16;π        end;π      end;π  end; { proc GetCharGenInfo }πππProcedure SetHardWareFont( font:ROMfont );π  beginπ    if isEGA thenπ      beginπ        Case Font ofπ          ROM8x14 : reg.AL := $11;π          ROM8x8  : reg.AL := $12;π          ROM8X16 : if isVGA thenπ                      reg.AL := $14π                    elseπ                      beginπ                        reg.AL := $12;π                        font := ROM8x14;π                      end;π        end;π        reg.BL := 0;π        intr( $10,reg );π        CurrentFont := font;π      end;π  end; { proc SetHardwareFont }πππFunction FetchHardwareFont( font:ROMfont ):FontPackagePtr;π  { Get a hardware font and place it on heap For user modification }π  Var pkg : FontPackagePtr;π  beginπ    new( pkg );π    GetCharGenInfo( font,pkg^.fontinfo );π    pkg^.ch := pkg^.fontinfo.def^;π    FetchHardwareFont := pkg;π  end; { func FetchHardwareFont }πππProcedure LoadUserFont( pkg:FontPackagePtr );π  beginπ    reg.AH := $11;π    Reg.AL := $10;π    reg.ES := seg( pkg^.ch );π    reg.BP := ofs( pkg^.ch );π    reg.BH := pkg^.FontInfo.points;π    reg.BL := 0;π    reg.CX := 256;π    reg.DX := 0;π    intr( $10,reg );π  end; { proc LoadUserFont }πππbegin  { initialize }ππ  { determine adapter Type }π  isEGA := False;π  isVGA := False;π  if VDA.info <> 0 thenπ    beginπ      isEGA := True;π      if ( VDA.flags and 1 ) = 1 thenπ        isVGA := True;π    end;ππ  { determine monitor Type }π  if isEGA thenπ    beginπ      reg.AH := $12;π      reg.BL := $10;π      intr( $10,reg );π      if reg.BH = 0 thenπ        isCOLOR := Trueπ      elseπ        isCOLOR := False;π                                   { ADM: this seems Really shaky! }π      { determine current font }π      if isVGA and ( VDA.rows = 24 ) thenπ        CurrentFont := ROM8x16π      elseπ        if isEGA and ( VDA.rows = 24 ) thenπ          CurrentFont := ROM8x14π        elseπ          CurrentFont := ROM8x8;π    endπend.π                                                                                                  4      05-28-9313:39ALL                      SWAG SUPPORT TEAM        CARDDETC.PAS             IMPORT              18          {πEDWIN CALIMBOππ│Can anyone supply me With a routine to determine a Graphics card? I wantπ│the Procedure to return a Variable if the user has a Graphics card lessπ│than an EGA. Anyone have anything quick?ππThe Function below will detect most Graphics (mono/color) card. It'sπa bit long, but is has all the info on how to detect certain card.π}ππUsesπ  Dos;ππTypeπ  CardType = (none,mda,cga,egamono,egacolor,π              vgamono,vgacolor,mcgamono,mcgacolor);ππFunction VideoCard: CardType;πVarπ  code : Byte;π  Regs : Registers;πbeginπ  Regs.AH := $1A;      (* call VGA Identify Adapter Function *)π  Regs.AL := $00;      (* clear AL to 0...*)π  Intr($10, Regs);     (* call BIOS *)π  If Regs.AL = $1A thenπ  beginπ    Case Regs.BL ofπ      $00 : VideoCard := NONE;       (* no Graphic card *)π      $01 : VideoCard := MDA;        (* monochrome *)π      $02 : VideoCard := CGA;        (* cga *)π      $04 : VideoCard := EGAColor;   (* ega color *)π      $05 : VideoCard := EGAMono;    (* ega mono*)π      $07 : VideoCard := VGAMono;    (* vga mono *)π      $08 : VideoCard := VGAColor;   (* vga color *)π      $0A,π      $0C : VideoCard := MCGAColor;  (* mcga color *)π      $0B : VideoCard := MCGAMono;   (* mcga mono *)π      Elseπ        VideoCard := CGAπ    endπ  endπ  Elseπ  beginπ    Regs.AH := $12;         (* use another Function service *)π    Regs.BX := $10;         (* BL = $10 means return EGA info *)π    Intr($10, Regs);        (* call BIOS video Function *)π    If Regs.bx <> $10 Then  (* bx unchanged means EGA is not present *)π    beginπ      Regs.AH := $12;π      Regs.BL := $10;π      Intr($10, Regs);π      If Regs.BH = 0 Thenπ        VideoCard := EGAColorπ      Elseπ        VideoCard := EGAMonoπ    endπ    Elseπ    beginπ      Intr($11, Regs);     (* eguipment determination service *)π      code := (Regs.AL and $30) shr 4;π      If (code = 3) Thenπ        VideoCard := MDAπ      Elseπ        VideoCard := CGAπ    endπ  endπend; (* VideoCard *)ππ(*============================= cut here ==================================*)ππbeginπ  Case VideoCard ofπ    VGAColor : Writeln('VGA Color');π  end;πend.                                                 5      05-28-9313:39ALL                      SWAG SUPPORT TEAM        CIRCLE.PAS               IMPORT              19          { SC> I had some free time the other day so I decided to play aroundπ SC> With some Graphics.  I am using TRIG Functions to draw aπ SC> circle.  But it's not too fast.  I understand that usingπ SC> Shift operators to multiply and divide will be faster.  Butπ SC> am not sure how to do numbers which are not powers of 2.π SC> Here is the code; how else can we make it faster?ππUsing shifts to multiply things is one way to speed it up but that's difficultπFor generic multiplies and only applies to Integer multiplies.  There's an evenπfaster way to draw a circle if you are interested. <YES he says>  OK, first itπis called the "Bresenham Circle Algorithm" and Uses symmetry about the eightπoctants to plot the circle and Uses only Integer arithmetic throughout.  Hereπis the code.π}πUsesπ  Graph, KASUtils;ππVarπ  Gd, Gm : Integer;ππProcedure DrawCircle(X, Y, Radius:Word; Color:Byte);πVarπ   Xs, Ys    : Integer;π   Da, Db, S : Integer;πbeginπ     if (Radius = 0) thenπ          Exit;ππ     if (Radius = 1) thenπ     beginπ          PutPixel(X, Y, Color);π          Exit;π     end;ππ     Xs := 0;π     Ys := Radius;ππ     Repeatπ           Da := Sqr(Xs+1) + Sqr(Ys) - Sqr(Radius);π           Db := Sqr(Xs+1) + Sqr(Ys - 1) - Sqr(Radius);π           S  := Da + Db;ππ           Xs := Xs+1;π           if (S > 0) thenπ                Ys := Ys - 1;ππ           PutPixel(X+Xs-1, Y-Ys+1, Color);π           PutPixel(X-Xs+1, Y-Ys+1, Color);π           PutPixel(X+Ys-1, Y-Xs+1, Color);π           PutPixel(X-Ys+1, Y-Xs+1, Color);π           PutPixel(X+Xs-1, Y+Ys-1, Color);π           PutPixel(X-Xs+1, Y+Ys-1, Color);π           PutPixel(X+Ys-1, Y+Xs-1, Color);π           PutPixel(X-Ys+1, Y+Xs-1, Color);π     Until (Xs >= Ys);πend;ππ{It Uses Sqr at the moment, but you could code it to use X * X instead of Sqr(X)πif you like since it will probably speed it up.  I haven't had time to optimiseπit yet since it will ultimately be in Assembler.ππHope this comes in handy For what you're doing. :-) Oh BTW it assumes you haveπa PlotDot routine which takes the obvious parameters.π}ππbeginπ  EGAVGA_Exe;π  gd := detect;π  InitGraph(gd,gm,'');π  clearviewport;ππ  drawcircle(100,100,150,yellow);π  readln;πend.                                                                                                        6      05-28-9313:39ALL                      SWAG SUPPORT TEAM        DAC-REGS.PAS             IMPORT              24          {πWould anyone have a Procedure of Function to do a fadein orπfadeout CLXXof a bitmapped image.  if I understand correctly, theseπCLXXfadeins are perFormed by changing the DAC Registers of the CLXXVGAπCards.  Can anyone enlighten me on this as I have CLXXsearched manyπbooks on how to do this and have not found CLXXit.  I know that there isπa utility out there called CLXXFastGraph by Teg Gruber which can doπthis, but short of CLXXbuying it For $200.00 Would one of you good folksπhave a CLXXroutint in Asm or BAsm to do this. CLXXI thank you all inπadvance For your assistance. CLXXChristian Laferriere.π}ππProcedure Pageswitch(X: Byte);πbeginπ  Asmπ    mov ah,5π    mov al,xπ    int 10hπ  end;πend; { Pageswitch }ππ{********************************************}πProcedure FadeIn;ππVarπ  oldp,π  oldp2,π  oldp3       : Byte;π  Palette     : Array[1..255 * 4] of Byte;π  FAKEPalette : Array[1..255 * 4] of Byte;π  I, J : Integer;ππbeginπ  For I := 1 to 255 doπ  beginπ    Port[$3C7] := I;π    Palette[(I - 1) * 4 + 1] := I;π    Palette[(I - 1) * 4 + 2] := Port[$3C9];π    Palette[(I - 1) * 4 + 3] := Port[$3C9];π    Palette[(I - 1) * 4 + 4] := Port[$3C9];π  end;π  For I := 1 to 255 doπ  beginπ    Port[$3C8] := I;π    Port[$3C9] := 0;π    Port[$3C9] := 0;π    Port[$3C9] := 0;π  end;ππ  Pageswitch(0);ππ  For J := 0 to 63 doπ  beginππ    For I := 1 to 255 doπ    beginπ      Port[$3C7] := I;π      oldp  := Port[$3C9];π      oldp2 := Port[$3C9];π      oldp3 := Port[$3C9];π      Port[$3C8] :=I;π      if oldp + 1 <= Palette[(I - 1) * 4 + 2] thenπ        Port[$3C9] := oldp+1π      elseπ        Port[$3C9] := Oldp;π      if oldp2 + 1 <= Palette[(I - 1) * 4 + 3] thenπ        Port[$3C9] := oldp2+1π      elseπ        Port[$3C9] := Oldp2;π      if oldp3 + 1 <= Palette[(I - 1) * 4 + 4] thenπ        Port[$3C9] := oldp3+1π      elseπ        Port[$3C9] := Oldp3;π    end;ππ    For I := 1 to 30000 doπ    beginπ    end;ππ  end;πend; {end of FadeIn}πππProcedure FadeOut;ππVarπ  uoldp,π  uoldp2,π  uoldp3  : Byte;π  I, J : Integer;πbeginπ  Pageswitch(0);ππ  For J := 0 to 63 doπ  beginππ    For I := 1 to 255 doπ    beginπ      Port[$3C7] := I;π      uoldp  := Port[$3C9];π      uoldp2 := Port[$3C9];π      uoldp3 := Port[$3C9];π      Port[$3C8] := I;π      if uoldp - 1 >= 0 thenπ        Port[$3C9] := uoldp - 1π      elseπ        Port[$3C9] := uOldp;π      if uoldp2 - 1 >= 0 thenπ        Port[$3C9] := uoldp2 - 1π      elseπ        Port[$3C9] := uOldp2;π      if uoldp3 - 1 >= 0 thenπ        Port[$3C9] := uoldp3 - 1π      elseπ        Port[$3C9] := uOldp3;π    end;ππ    For I := 1 to 30000 doπ    beginπ    end;ππ  end;πend; {end of FadeOut}ππ{πThat Procedure can FadIn and FadeOut any Text screen or anyπGraphics in Mode $13 With no problems.. Just make sure that youπswitch the video pages at the right time between fadeIns andπFadeouts.. Hope that helped.. LATERπ}ππbeginπ  FadeOut;π  FadeIn;πend.                                            7      05-28-9313:39ALL                      SWAG SUPPORT TEAM        DACCOLOR.PAS             IMPORT              7           {π Here is some code to try For Text fading on a vga...π by Sean Palmerπ}ππConstπ  tableReadIndex    = $3C7;π  tableWriteIndex   = $3C8;π  tableDataRegister = $3C9;ππProcedure setColor(color, r, g, b : Byte); Assembler;πAsm {set DAC color}π  mov dx, tableWriteIndex;π  mov al, color;π  out dx, al;π  inc dx;π  mov al, r;π  out dx, al;π  mov al, g;π  out dx, al;π  mov al, b;π  out dx, al;πend; {Write index now points to next color}ππFunction getColor(color : Byte) : LongInt; Assembler;πAsm {get DAC color}π  mov dx, tableReadIndex;π  mov al, color;π  out dx, al;π  add dx, 2;π  cld;π  xor bh, bh;π  in al, dx;π  mov bl, al;π  in al, dx;π  mov ah, al;π  in al, dx;π  mov dx, bx;πend; {read index now points to next color}ππ                                            8      05-28-9313:39ALL                      SWAG SUPPORT TEAM        EGAPALET.PAS             IMPORT              6           {π> I once saw a Procedure that set the palette With RGB inputs, like theπ> 256- colour palette setter (RGBSetPalette).  It used some SHLsπ> and SHRs to reduce the inputted values For red, green, andπ> blue to 2-bit values (or somewhere around there).π}ππProcedure EGAPalette(c_index, red, green, blue : Byte);πVarπ  i    : Integer;π  regs : Registers;πbeginπ  red   := red SHR 6;π  green := green SHR 6;π  blue  := blue SHR 6;π  i     := (red SHL 4) + (green SHL 2) + blue;π  regs.AH := $10;π  regs.AL := 0;π  regs.BH := i;π  regs.BL := c_index;  { the colour index to change }π  Intr($10, regs);πend;ππ                                    9      05-28-9313:39ALL                      SWAG SUPPORT TEAM        FADE.PAS                 IMPORT              15          Program GoodFade;πUsesπ  Crt;ππConstπ  I1II111 = 75;π  IIIIII = 60;ππVarπ  Count, Count2 : Byte;π  Pal1, Pal2 : Array [0..255, 0..2] of Byte;ππProcedure I1I1;πbeginπ  For Count := 0 to 255 DOπ  beginπ    PORT [$03C7] := Count;π    Pal1 [Count, 0] := PORT [$03C9];π    Pal1 [Count, 1] := PORT [$03C9];π    Pal1 [Count, 2] := PORT [$03C9];π   end;π  Pal2 := Pal1;πend;ππProcedure IIIIIII;πbeginπ  For Count := 0 to 255 DOπ  beginπ    PORT [$03C8] := Count;π    PORT [$03C9] := Pal1 [Count, 0];π    PORT [$03C9] := Pal1 [Count, 1];π    PORT [$03C9] :=π    Pal1 [Count, 2];π  end;πend;ππProcedure FadeOut;πbeginπ  For Count := 1 to I1II111 DOπ  beginπ    For Count2 := 0 to 255 DOπ    beginπ      if Pal2 [Count2, 0] > 0 thenπ        DEC (Pal2 [Count2, 0]);π      if Pal2 [Count2, 1] > 0 thenπ        DEC (Pal2 [Count2, 1]);π      if Pal2 [Count2, 2] > 0 thenπ        DEC (Pal2 [Count2, 2]);π      PORT [$03C8] := Count2;π      PORT [$03C9] := Pal2 [Count2, 0];π      PORT [$03C9] := Pal2 [Count2, 1];π      PORT [$03C9] := Pal2 [Count2, 2];π    end;π    Delay (IIIIII);π  end;πend;ππProcedure FadeIn;πbeginπ  For Count := 1 to I1II111 DOπ  beginπ    For Count2 := 0 to 255 DOπ    beginπ      if Pal2 [Count2, 0] < Pal1 [Count2, 0] thenπ        INC (Pal2 [Count2, 0]);π      if Pal2 [Count2, 1] < Pal1 [Count2, 1] thenπ        INC (Pal2 [Count2, 1]);π      if Pal2 [Count2, 2] < Pal1 [Count2, 2] thenπ        INC (Pal2 [Count2, 2]);π      PORT [$03C8] := Count2;π      PORT [$03C9] := Pal2 [Count2, 0];π      PORT [$03C9] := Pal2 [Count2, 1];π      PORT [$03C9] := Pal2 [Count2, 2];π    end;π    Delay (IIIIII);π  end;πend;ππbeginπ  I1I1;π  FadeOut;π  FadeIn;π  IIIIIII;πend.ππ                                                                                                                       10     05-28-9313:39ALL                      SWAG SUPPORT TEAM        FADING.PAS               IMPORT              61          {πEirik Milch Pedersenππ> I too, would appreciate the source for fading colours in 16 colour textπ> mode on a VGA, i've tried my hand at it but can't work out a decentπ> algoritm, i've been using int 10h to set a block of colour regs for speedπ> but can't seem to work out how to fade the colours!ππI replyed to the author of the first fade-question, but I might as well postπmy code to the public. This is a little demo I made in TP60 for fading form aπpalette to another. So techincal you can fade from anything to anything. :-)πThe routine should be fast enough for most computers, but if you start toπsee 'snow' on the screen try to reduce the number of colors that are faded.π}ππ{$G+}πusesπ  crt;ππtypeπ  ColorType = array[0..255] of recordπ                                 R, G, B : byte;π                               end;ππvarπ  Colors,π  White,π  Black   : ColorType;ππprocedure SetMode(Mode : word); assembler;πasmπ  mov  ax, Modeπ  int  010hπend;ππprocedure MakeColors(ColorArray : pointer); assembler;πlabelπ  RLoop, GLoop, BLoop;πasmπ  les  di, ColorArrayππ  mov  cx, 85π  xor  al, alπ RLoop:π  mov  byte ptr es:[di+0], alπ  mov  byte ptr es:[di+1], 0π  mov  byte ptr es:[di+2], 0π  add  di, 3π  inc  alπ  and  al, 03Fhπ  loop Rloopππ  mov  cx, 85π  xor  al, alπ GLoop:π  mov  byte ptr es:[di+0], 0π  mov  byte ptr es:[di+1], alπ  mov  byte ptr es:[di+2], 0π  add  di, 3π  inc  alπ  and  al, 03Fhπ  loop Gloopππ  mov  cx, 86π  xor  al, alπ BLoop:π  mov  byte ptr es:[di+0], 0π  mov  byte ptr es:[di+1], 0π  mov  byte ptr es:[di+2], alπ  add  di, 3π  inc  alπ  and  al, 03Fhπ  loop Bloopπend;ππprocedure DrawBars; assembler;πlabelπ  LineLoop, PixelLoop;πasmπ  mov  ax, 0A000hπ  mov  es, axπ  xor  di, diππ  mov  cx, 200π LineLoop:π  xor  al, alπ  push cxπ  mov  cx, 320π PixelLoop:π  stosbπ  inc  alπ  loop PixelLoopππ  pop  cxπ  loop LineLoopπend;ππprocedure UpdateColorsSlow(ColorBuffer : pointer); assembler;πlabelπ  ColorLoop;πasmπ  push dsππ  lds  si, ColorBufferπ  mov  cx, 3*256ππ  mov  dx, 03C8hπ  xor  al, alπ  out  dx, alπ  inc  dxπ ColorLoop:                         { here is the substitute that }π  lodsb                      { goes round the problem.     }π  out  dx, alπ  loop ColorLoopππ  pop  dsπend;ππprocedure UpdateColorsFast(ColorBuffer : pointer); assembler;πasmπ  push dsππ  lds  si, ColorBufferπ  mov  cx, 3*256ππ  mov  dx, 03C8hπ  xor  al, alπ  out  dx, alπ  inc  dxππ  rep  outsb              { here is the cause of the problem. }ππ  pop  dsπend;πππprocedure FadeColors(FromColors, ToColors : Pointer;π                     StartCol, NoColors, NoSteps : byte); assembler;πlabelπ  Start, DummyPalette, NoColorsX3,π  DummySub, StepLoop, ColorLoop,π    SubLoop, RetrLoop1, RetrLoop2, Over1, Over2;πasmπ    jmp    Startπ DummyPalette:π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π DummySub:π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π    db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π  db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0π NoColorsX3 :π  dw      0π Start:π    push dsππ    lds     si, ToColorsπ  les     di, FromColorsπ  xor  ch, chπ  mov     cl, NoColorsπ  shl     cx, 1π  add     cl, NoColorsπ  adc  ch, 0π  mov     word ptr cs:[NoColorsX3], cxπ  mov     bx, 0π  push diπ SubLoop:π    lodsbπ    sub     al, byte ptr es:diπ    mov     byte ptr cs:[DummySub+bx], alπ  inc     diπ  inc     bxπ    loop SubLoopπ  pop     diππ  push csπ  pop     dsπ    mov     dh, 0π  mov  dl, NoStepsπ StepLoop:π  push diπ  mov     cx, word ptr cs:[NoColorsX3]π  mov     bx, 0π ColorLoop:π  xor     ah, ahπ    mov     al, byte ptr cs:[DummySub+bx]π  or     al, alπ  jns     over1π  neg     alπ over1:π  mul     dhπ  div     dlπ  cmp  byte ptr cs:[DummySub+bx], 0π  jge     over2π  neg     alπ over2:π  mov     ah, byte ptr es:[di]π  add     ah, alπ  mov     byte ptr cs:[DummyPalette+bx], ahπ  inc     bxπ  inc     diπ  loop ColorLoopππ  push dxπ  mov  si, offset DummyPaletteπ  mov  cx, word ptr cs:[NoColorsX3]ππ  mov  dx, 03DAhπ retrloop1:π  in      al, dxπ  test al, 8π  jnz  retrloop1π retrloop2:π  in      al, dxπ  test al, 8π  jz   retrloop2ππ  mov  dx, 03C8hπ  mov  al, StartColπ  out  dx, alπ  inc  dxπ  rep     outsbππ  pop     dxππ  pop     diπ  inc     dhπ  cmp     dh, dlπ  jbe     StepLoopππ  pop     dsπend;ππππbeginπ  ClrScr;π  MakeColors(@Colors);π  FillChar(Black, 256 * 3, 0);π  FillChar(White, 256 * 3, 63);ππ  SetMode($13);π  UpdateColorsSlow(@Black);π  DrawBars;ππ  REPEATπ    FadeColors(@Black, @Colors, 0, 255, 100);π    FadeColors(@Colors, @White, 0, 255, 100);π    FadeColors(@White, @Colors, 0, 255, 100);π    FadeColors(@Colors, @Black, 0, 255, 100);π  UNTIL keyPressed;ππ  SetMode($3);πEND.π                                                                                                            11     05-28-9313:39ALL                      SWAG SUPPORT TEAM        FASTRGB.PAS              IMPORT              6           {πGRADY WERNERπPut these in your code For GREAT, FAST RGB Palette Changing...π}πProcedure ASetRGBPalette(Color, Red, Green, Blue : Byte);πbeginπ  Port[$3C8]:=Color;π  Port[$3C9]:=Red;π  Port[$3C9]:=Green;π  Port[$3C9]:=Blue;πend;ππ{πThis Procedure Changes palette colors about 400% faster than theπbuilt-in routines.  Also, a problem With flicker may have been encounteredπwith Turbo's Putimage Functions.  Call this Procedure RIGHT BEFORE theπputimage is called... Viola... NO Flicker!π}πProcedure WaitScreen;πbeginπ  Repeat Until (Port[$3DA] and $08) = 0;π  Repeat Until (Port[$3DA] and $08) <> 0;πend;π                                   12     05-28-9313:39ALL                      SWAG SUPPORT TEAM        GETMODE1.PAS             IMPORT              6           {πHere's a quick proc. to return the current video mode:π}ππUsesπ  Dos;ππFunction CurVidMode : Byte;ππVarπ  Regs : Registers;ππbegin;ππ  Regs.Ah :=$f;π  Intr($10, Regs);π  CurVidMode := Regs.Al;ππend;ππbeginπ  Writeln(CurVidMode);πend.πππ{πYou can use that same color Procedure For the VGA 16 color mode becauseπalthough it can only do 16 colors, it can still change each of the 16πcolors to 64*64*64 (262,144) colors, like the 256 color mode.ππAbout the EGA palette - I'll have to get back to ya, that's moreπcomplex.π}ππ                                                                                                                      13     05-28-9313:39ALL                      SWAG SUPPORT TEAM        GOODFADE.PAS             IMPORT              12          {π>I have a copy of the fade Unit and am having problems getting it to workπ>correctly. I want to fade my Programs screen on Exit, clear it, and showπ>the Dos screen.ππHere's a little fade source, there're some change to made if you're using it inπGraphic or Text mode.π}ππUsesπ  Crt;πππVarπ  count1, count2 : Integer;π  pal1,pal2 : Array[0..255,0..2] of Byte;πππbeginππ  For count1 := 0 to 255 do           {Get the current palette}π  beginπ    Port[$03C7] := count1;π    pal1[count1,0] := Port[$03C9];π    pal1[count1,1] := Port[$03C9];π    pal1[count1,2] := Port[$03C9];π  end;ππ  Pal2:=Pal1;ππ  For Count1 := 1 to 255 do           {this will fade the entire palette}π  begin                               {20 must be enough in Text mode}π    For Count2 := 0 to 255 doπ    beginπ      If Pal2[Count2,0] > 0 thenπ        Dec(Pal2[Count2,0]);π      If Pal2[Count2,1] > 0 thenπ        Dec(Pal2[Count2,1]);π      If Pal2[Count2,2] > 0 thenπ        Dec(Pal2[Count2,2]);π      Port[$03C8] := Count2;π      Port[$03C9] := Pal2[Count2,0];π      Port[$03C9] := Pal2[Count2,1];π      Port[$03C9] := Pal2[Count2,2];π    end;π    Delay(40);         {Change the Delay For a quicker or slower fade}π  end;ππ  For Count1 := 0 to 255 do   {Restore Original palette}π  beginπ    Port[$03C8] := Count1;π    Port[$03C9] := Pal1[Count1,0];π    Port[$03C9] := Pal1[Count1,1];π    Port[$03C9] := Pal1[Count1,2];π  end;ππend.ππ 14     05-28-9313:39ALL                      SWAG SUPPORT TEAM        GREATFAD.PAS             IMPORT              17          {πJohn Wongππ>Does anyone out there have any fade-in routines??? Also can anyoneπ>recomend some good books on VGA Programming and Animation???ππThis might be a fade out routine, but you could modify it to fade in.π}π{$G+}πProgram fades;ππUsesπ  Crt, Dos;π                  { TPC /$G+ To Compile }πVarπ  All_RGB : Array[1..256 * 3] Of Byte;π  x,color : Integer;πππProcedure FadeOut2; { This is Hard Cores Fade Out }πbeginπ  {for using Textmode use color 7, or For Graphics}π  x := 1;π  Color := 7;π  Repeat;π    port[$3c8] := color;π    port[$3c9] := 60 - x;π    port[$3c9] := 60 - x;π    port[$3c9] := 60 - x;π    inc(x);π    Delay(75);π  Until x = 60;ππ         { Get The Screen Back ( Change This ) }π  Color := 7;π  port[$3c8] := color;π  port[$3c9] := 60 + x;π  port[$3c9] := 60 + x;π  port[$3c9] := 60 + x;π  inc(x);π  Delay(25);πend;ππProcedure FadeOut;πLabelπ  OneCycle,π  ReadLoop,π  DecLoop,π  Continue,π  Retr,π  Wait,π  Retr2,π  Wait2;πbegin { FadeOut }π  Asmπ    MOV   CX,64π  OneCycle:ππ    MOV     DX,3DAhπ  Wait:   in      AL,DXπ    TEST    AL,08hπ    JZ      Waitπ  Retr:   in      AL,DXπ    TEST    AL,08hπ    JNZ     Retrππ    MOV   DX,03C7hπ    xor   AL,ALπ    OUT   DX,ALπ    INC   DXπ    INC   DXπ    xor   BX,BXπ  ReadLoop:π    in    AL,DXπ    MOV   Byte Ptr All_RGB[BX],ALπ    INC   BXπ    CMP   BX,256*3π    JL    ReadLoopππ    xor   BX,BXπ  DecLoop:π    CMP   Byte Ptr All_RGB[BX],0π    JE    Continueπ    DEC   Byte Ptr All_RGB[BX]ππ  Continue:π    INC   BXπ    CMP   BX,256*3π    JL    DecLoopππ    MOV     DX,3DAhπ  Wait2:   in      AL,DXπ    TEST    AL,08hπ    JZ      Wait2π  Retr2:   in      AL,DXπ    TEST    AL,08hπ    JNZ     Retr2ππ    MOV   DX,03C8hπ    MOV   AL,0π    OUT   DX,ALπ    INC   DXπ    MOV   SI,OFFSET All_RGBπ    CLDπ    PUSH  CXπ    MOV   CX,256*3π    REP   OUTSBπ    POP   CXππ    LOOP  OneCycleππ  end;πend; { FadeOut }πππbeginπ  fadeout;π  NormVideo;π  Fadeout2;πend.π                                                                                                                               15     05-28-9313:39ALL                      SWAG SUPPORT TEAM        GRPHINIT.PAS             IMPORT              18          {πThe following Unit contains one Function.  This Function will initialize theπBorland BGI Interface in a Turbo Pascal Program.  I wrote this Unit in TPπ5.5, but it should work For all versions of TP after 4.0.ππThe Function performs two actions which I think can help Graphics Programsπimmensely.  The first is to obtain the path For the BGI (and CHR) driversπfrom an environmental Variable BGIDIR.  The second action is to edit theπdriver and mode passed to the initialization Unit against what is detectedπby TP.  The Function returns a Boolean to say if it was able to successfullyπinitialize the driver.ππI hope this helps someone.π}ππUnit GrphInit;ππInterfaceππUsesπ    Dos,π    Graph;ππFunction Init_Graphics (Var GraphDriver, GraphMode : Integer) : Boolean;π{    This Function will initialize the Turbo Graphics For the requestedπ    Graphics mode if and only if the requested mode is valid For theπ    machine the Function is run in.  Another feature of this Function isπ    that it will look For an environmental Variable named 'BGIDIR'.  Ifπ    this Variable is found, it will attempt to initialize the Graphicsπ    mode looking For the BGI driver using the String associated With BGIDIRπ    as the path.  If the correct BGI driver is not available, or if there isπ    not BGIDIR Variable in the environment, it will attempt to initializeπ    using the current directory. }πππImplementationππFunction Init_Graphics (Var GraphDriver, GraphMode : Integer) : Boolean;πConstπ    ENV_BGI_PATH = 'BGIDIR';πVarπ    BGI_Path    : String;πbeginπ    { Default to not work }π    Init_Graphics := False;π  BGI_Path := GetEnv(ENV_BGI_PATH);π    InitGraph(GraphDriver,GraphMode,BGI_Path);π    if GraphResult = grOk thenπ         Init_Graphics := Trueπ    Elseπ  begin { Try current Directory }π        InitGraph(GraphDriver,GraphMode,'');π        if GraphResult = grOk thenπ            Init_Graphics := True;π    end; { Try current Directory }πend; { Function Init_Graphics }ππend.πππ{π Example File :ππUsesπ  Graph, GrphInit;ππConstπ  Gd     : Integer = 0;π  Gm     : Integer = 0;πbeginπ  Init_Graphics(Gd, Gm);π  Line(10,10,40,40);π  Readln;πend.π}                                                                                                                    16     05-28-9313:39ALL                      SWAG SUPPORT TEAM        IMAGEPUT.PAS             IMPORT              25          {Here is a small Program that illustrates the features of GetImage/PutImage thatπyou would like to use:π}π {$A+,B-,D+,E-,F-,G+,I-,L+,N-,O-,R-,S+,V-,X+}π {$M 16384,0,655360}π Uses Graph;π (* Turbo Pascal, Width= 20 Height= 23 Colors= 16 *)π Constπ   Pac: Array[1..282] of Byte = (π          $13,$00,$16,$00,$00,$FE,$00,$00,$FE,$00,π          $00,$FE,$00,$FF,$01,$FF,$03,$FF,$80,$03,π          $FF,$80,$03,$FF,$80,$FC,$00,$7F,$07,$8F,π          $C0,$07,$8F,$C0,$07,$8F,$C0,$F8,$00,$3F,π          $1F,$77,$F0,$1F,$17,$F0,$1F,$17,$E0,$E0,π          $70,$0F,$1F,$77,$E0,$1F,$37,$E0,$1F,$37,π          $C0,$E0,$70,$1F,$3F,$77,$C0,$3F,$17,$C0,π          $3F,$17,$80,$C0,$70,$3F,$7F,$8F,$80,$7F,π          $8F,$80,$7F,$8F,$00,$80,$00,$7F,$7F,$FF,π          $00,$7F,$FF,$00,$7F,$FE,$00,$80,$00,$FF,π          $FF,$FE,$00,$FF,$FE,$00,$FF,$FC,$00,$00,π          $01,$FF,$FF,$FC,$00,$FF,$FC,$00,$FF,$F8,π          $00,$00,$03,$FF,$FF,$F8,$00,$FF,$F8,$00,π          $FF,$F0,$00,$00,$07,$FF,$FF,$F0,$00,$FF,π          $F0,$00,$FF,$E0,$00,$00,$0F,$FF,$FF,$F8,π          $00,$FF,$F8,$00,$FF,$F0,$00,$00,$07,$FF,π          $FF,$FC,$00,$FF,$FC,$00,$FF,$F8,$00,$00,π          $03,$FF,$FF,$FE,$00,$FF,$FE,$00,$FF,$FC,π          $00,$00,$01,$FF,$7F,$FF,$00,$7F,$FF,$00,π          $7F,$FE,$00,$80,$00,$FF,$7F,$FF,$80,$7F,π          $FF,$80,$7F,$FF,$00,$80,$00,$7F,$3F,$FF,π          $C0,$3F,$FF,$C0,$3F,$FF,$80,$C0,$00,$3F,π          $1F,$FF,$E0,$1F,$FF,$E0,$1F,$FF,$C0,$E0,π          $00,$1F,$1F,$FF,$F0,$1F,$FF,$F0,$1F,$FF,π          $E0,$E0,$00,$0F,$07,$FF,$C0,$07,$FF,$C0,π          $07,$FF,$C0,$F8,$00,$3F,$03,$FF,$80,$03,π          $FF,$80,$03,$FF,$80,$FC,$00,$7F,$00,$FE,π          $00,$00,$FE,$00,$00,$FE,$00,$FF,$01,$FF,π          $00,$00);π Var Size,Result: Word;π     Gd, Gm: Integer;π     P: Pointer;π     F: File;π beginπ { Find correct display/card-Type and initiallize stuff }π   Gd := Detect;π   InitGraph(Gd, Gm, 'd:\bp\bgi');π   if GraphResult <> grOk then Halt(1); { Error initialize }π   ClearDevice;ππ   SetFillStyle(SolidFill,Blue);π   Bar(0,0,639,479);π   P := @Pac;                                (* Pass the address of the   *)π                                             (* Pac Constant to a Pointer *)π   PutImage(1,1,P^,NormalPut);               (* Display image             *)ππ   Size := ImageSize(1,1,20,23) { Get size of your picture };π   GetMem(P, Size); { Get memory from heap }π   GetImage(1,1,20,23,P^) { Capture picture itself in P^ };ππ   ClearDevice;ππ   Assign(F,'IMAGE');π   reWrite(F,1);π   BlockWrite(F,P^,Size,Result) { Put picture (from P^) in File F };π   if Ioresult <> 0 then Halt(2) { Error during BlockWrite I/O };π   if Result <> Size then Halt(3) { not enough data written to F };π   close(F);π   if Ioresult <> 0 then Halt(4) { Error during Close of F };ππ   PutImage(1,1,P^,NormalPut);π   FreeMem(P,Size) { Free memory. This is GPP. };π   ReadLn { Hit any key to continue };π   ClearDevice;π   CloseGraph;π end.π                                                                                                                              17     05-28-9313:39ALL                      SWAG SUPPORT TEAM        LINEDRAW.PAS             IMPORT              19          {1)  An efficient/optimised line-drawing routine (in Pascalπor Asm) based on (or better than) the Bres. Line algorithm.π}ππ{$R-,S-}ππUsesπ  Crt, Dos;ππProcedure PutPixel(X, Y : Word; Color : Byte);πbeginπ  Mem[$A000:Y*320+X] := Colorπend;ππProcedure Switch(Var First, Second : Integer);π{ Exchange the values of First and second }πVarπ  Temp : Integer;πbeginπ  Temp := First;π  First := Second;π  Second := Temp;πend; { Switch }ππProcedure Line(X1, Y1, X2, Y2, Color : Integer);π{ Uses Bressenham's algorithm For drawing a line }πVarπ  LgDelta, ShDelta, LgStep, ShStep, Cycle, PointAddr : Integer;ππbeginπ  LgDelta := X2 - X1;π  ShDelta := Y2 - Y1;π  if LgDelta < 0 thenπ    beginπ      LgDelta := -LgDelta;π      LgStep := -1;π    endπ  elseπ    LgStep := 1;π  if ShDelta < 0 thenπ    beginπ      ShDelta := -ShDelta;π      ShStep := -1;π    endπ  elseπ    ShStep := 1;π  if LgDelta > ShDelta thenπ    beginπ      Cycle := LgDelta shr 1; { LgDelta / 2 }π      While X1 <> X2 doπ      beginπ        Mem[$A000:Y1*320+X1] := Color; { PutPixel(X1, Y1, Color); }π        Inc(X1, LgStep);π        Inc(Cycle, ShDelta);π        if Cycle > LgDelta thenπ        beginπ          Inc(Y1, ShStep);π          Dec(Cycle, LgDelta);π        end;π      end;π    endπ  elseπ    beginπ      Cycle := ShDelta shr 1; { ShDelta / 2 }π      Switch(LgDelta, ShDelta);π      Switch(LgStep, ShStep);π      While Y1 <> Y2 doπ      beginπ        Mem[$A000:Y1*320+X1] := Color; { PutPixel(X1, Y1, Color); }π        Inc(Y1, LgStep);π        Inc(Cycle, ShDelta);π        if Cycle > LgDelta thenπ        beginπ          Inc(X1, ShStep);π          Dec(Cycle, LgDelta);π        end;π      end;π    end;πend; { Line }ππProcedure SetMode(Mode : Byte);π{ Interrupt $10, sub-Function 0 - Set video mode }πVarπ  Regs : Registers;πbeginπ  With Regs doπ  beginπ    AH := 0;π    AL := Mode;π  end;π  Intr($10, Regs);πend; { SetMode }ππVarπ  x,y,d:Word;π  r:Real;ππbegin   { example }π  SetMode($13);  { 320x200 256 color mode For VGA and MCGA cards }π  For d := 0 to 360 * 10 doπ  beginπ     r := (d * PI) * 0.1 / 180;π     x := round(sin(r * 5) * 90) + 160;π     y := round(cos(r) * 90) + 100;π     line(160,100,x,y,x div 4);π  end;π  Repeat Until port[$60] = 1;    { hit esc to end }ππ  SetMode($03) { Text mode }πend.π                         18     05-28-9313:39ALL                      SWAG SUPPORT TEAM        MODE-XY1.PAS             IMPORT              25          {πFor people who do not find any xsharp Near them, and who would like to test itπanyway i translated some Assembler-Code (not by me) back to to TP6.πI tested it on a 486/33 With multisynch and a 386/40 With an old bw/vga monitorπboth worked well. Anyway i cannot guarantee that it works With every pc and isπhealthy For every monitor, so be careful.πThis Listing changes to 360x480x256 modex and displays some pixels.πHave fun With it !π}π(*Source: VGAKIT Version 3.4π   Copyright 1988,89,90 John Bridgesπ   Translated to Pascal (why?) by Michael Mrosowski *)ππProgram ModexTest;ππUses Crt,Dos;ππVarπ  maxx,maxy : Word;ππ(*Set Modex 360x480x256 *)ππProcedure SetModex;πConstπ VptLen=17;π Vpt : Array[1..VptLen] of Word =π                    ($6b00 , (* horz total                      *)π                     $5901 , (* horz displayed                  *)π                     $5a02 , (* start horz blanking             *)π                     $8e03 , (* end horz blanking               *)π                     $5e04 , (* start h sync                    *)π                     $8a05 , (* end h sync                      *)π                     $0d06 , (* vertical total                  *)π                     $3e07 , (* overflow                        *)π                     $4009 , (* cell height                     *)π                     $ea10 , (* v sync start                    *)π                     $ac11 , (* v sync end and protect cr0-cr7  *)π                     $df12 , (* vertical displayed              *)π                     $2d13 , (* offset                          *)π                     $0014 , (* turn off dWord mode             *)π                     $e715 , (* v blank start                   *)π                     $0616 , (* v blank end                     *)π                     $e317); (* turn on Byte mode               *)πVarπ  regs:Registers;π  i:Integer;π  cr11:Byte;πbeginπ  maxx:=360;π  maxy:=480;π  regs.ax:=$13;       (*start With standardmode 13h*)π  Intr($10,regs);     (*hi bios!*)ππ  PortW[$3c4]:=$0604; (*alter sequencer Registers: disable chain 4*)π  PortW[$3c4]:=$0F02; (*    set Write plane mask to all bit planes*)π  FillChar(Mem[$a000:0],43200,0); (* Clearscreen *)π                      (*  ((XSIZE*YSIZE)/(4 planes)) *)ππ  PortW[$3c4]:=$0100; (*synchronous reset*)π  Port [$3c2]:=$E7;   (*misc output : use 28 Mhz dot clock*)π  PortW[$3c4]:=$0300; (*sequencer   : restart*)ππ  Port [$3d4]:=$11;   (*select Crtc register cr11*)π  cr11:=Port[$3d5];π  Port [$3d5]:=cr11 and $7F; (*Write protect*)ππ  For i:=1 to vptlen do (*Write Crtc-Registers*)π    PortW[$3d4]:=Vpt[i];πend;πππ(*Put pixel in 360x480 (no check)*)ππProcedure PutPixel(x,y:Word;c:Byte);πbeginπ  PortW[$3c4]:=($100 shl (x and 3))+2; (*set EGA bit plane mask register*)π  Mem[$a000:y*(maxx shr 2) + (x shr 2)]:=c;πend;ππVar c:Char;π    i,j:Integer;ππbeginπ  SetModex;π  For j:=0 to 479 do  (* Nearly SVGA With your good old 256k VGA*)π    For i:=0 to 359 doπ      PutPixel(i,j,(i+j) and $FF);π  c:=ReadKey;π  TextMode(LastMode);πend.                      19     05-28-9313:39ALL                      SWAG SUPPORT TEAM        MODE-XY2.PAS             IMPORT              47          {πKai Rohrbacherππ>> Basically,  Mode  Y  works  like  this:  use  the BIOS to switchπ>> into normal 320x200x256  mode,  then reprogram the sequencer toπ>> unchain the 4 bitplanes. This  results  in  a bitplaned VRAM layoutπ>> very similiar to the EGA/VGA's 16 color modes:π>π> By saying 4 bitplanes, are you referering to the pages? I know thatπ> you can specify 4 pages in mode X/Y.ππNo, it just means that with each VRAM address, 4 physically different RAM cellsπcan be addressed: you may think of a "3-dimensional" architecture of your VGA'sπVRAM (ASCII sucks, I know...)π             ____________π            |*  plane3   |π         ___|_________   |π        |*   plane2   |__|π     ___|__________   |π    |*   plane1    |__|π ___|___________   |π|*   plane0     |__|π|               |π|_______________|ππThe upper left corner of each bitplane (marked by a "*") is referenced with theπaddress $A000:0, but refers to 4 pixels! It is quite simple: instead ofπcounting "$A000:0 is the first pixel, $A000:1 is the 2nd, $A000:2 is the 3rd,π$A000:3 is the 4th, $A000:4 is the 5th" (as you would do in the normal BIOSπmode 320x200x256), the pixels now are distributed this way: "$A000:0/plane 0 isπthe 1st, $A000:0/plane 1 is the 2nd, $A000:0/plane 2 is the 3rd, $A000:0/planeπ3 is the 4th, $A000:1/plane 0 is the 5th" and so on.πSo obviously, w/o doing some "bitplane switching", you are always restricted toπwork on one bitplane at a time --the one actually being activated. If this isπplane0, you may only change pixels which (x mod 4) remainder is 0, the otherπones with (x mod 4)=1|2|3 aren't accessible, you have to "switch to the plane"πfirst. Thus the name "bitplane"!ππDT> And what exactly does "unchain" mean, as opposed to "chained". I have theπDT> feeling that they refer to each page(bitplane) being on its own.πHuhh, that would go pretty much into details; a bit simplified, "chained" meansπthat the bitplanes mentioned above are "glued" together for the simple BIOSπmode, so that bitplane switching isn't necessary anymore (that is equivalent inπsaying that one VRAM address refers to one RAM cell). As there are only 65536πaddresses in the $A000 segment and we need 320x200=64000 for a full page, youπonly have 65536/64000=1.024 pages therefore. "Unchaining" means to make eachπbitplane accessible explicitely.ππ> Now here is another problem I don't understand. I am familiar with VGA'sπ> mode 13h which has one byte specifying each pixel on the screen,π> therefore 1 byte = 1 pixel. But this takes up 64k.ππSmall note on this: not 64K, but only 64000 bytes!ππ> But how do you have one address represent 4 pixels, which only occupiesπ> 16000 address bytes, and still be able to specify 256 colours. Won't 4π> bitplanes at 320x200 each take up 64000x4 bytes of space?ππWe have 320x200=64000 pixels=64000 bytes. As each 4 pixels share one address,π16000 address bytes per page suffice. The $A000 segment has 64K address bytes,πthus 4*64K=256K VRAM can be addressed. 64K address bytes = 65536 address bytes;π65536/16000 = 4.096 pages.ππ> How would you go about adjusting the vertical retraces, and memoryπ> location you mentioned.ππAssuming that the DX-register has been set to 3DAh or 3BAh for color/monochromeπdisplay, respectively, you can trace the status of the electronic beam likeπthis:ππ  @WaitNotVSyncLoop:π    in   al, dxπ    and  al, 8π    jnz  @WaitNotVSyncLoopπ  @WaitVSyncLoop:π    in   al, dxπ    and  al, 8π    jz   @WaitVSyncLoopπ  {now change the starting address}π{π(If you use "1" instead of "8" and exchange "jz" <-> "jnz" and vice vs., thenπyou sync on the shorter horizontal retrace (better: horizontal _enable_)πsignal).πThe alteration of the starting address is done by the code I already posted inπmy first mail! (Its done by addressing the registers $C and $D of theπCRT-controller).πNote that reprogramming the starting address isn't restricted to mode X/Y, youπcan have it in normal mode 13h, too: there are 65536 addresses available, butπonly 64000 needed, thus giving a scroll range of 4.8 lines! And to complicateπthings even further, for start addressing purposes, even the BIOS mode isπplaned (that is, a row consists of 320/4 bytes only). Just for the case youπdon't believe...π}πPROGRAM Scroll;πVARπ  CRTAddress,π  StatusReg   : WORD;π  a           : ARRAY[0..199, 0..319] OF BYTE ABSOLUTE $A000 : 0000;π  i, j        : WORD;ππPROCEDURE SetAddress(ad : WORD); ASSEMBLER;πASMπ  MOV BX, adππ  MOV DX, StatusRegπ  @WaitNotVSyncLoop:π    in   al, dxπ    and  al, 8π    jnz  @WaitNotVSyncLoopπ  @WaitVSyncLoop:π    in   al, dxπ    and  al, 8π    jz   @WaitVSyncLoopππ  MOV DX, CRTAddressπ  MOV AL, $0Dπ  CLIπ  OUT DX, ALπ  INC DXπ  MOV AL, BLπ  OUT DX, ALπ  DEC DXπ  MOV AL, $0Cπ  OUT DX, ALπ  INC DXπ  MOV AL, BHπ  OUT DX, ALπ  STIπEND;ππBEGINπ  IF ODD(port[$3CC]) THENπ    CRTAddress := $3D4π  ELSEπ    CRTAddress := $3B4;ππ  StatusReg := CRTAddress + 6;π  ASMπ    MOV AX,13hπ    INT 10hπ  END;ππ  FOR i := 1 TO 1000 DOπ   a[Random(200), Random(320)] := Random(256);ππ  {scroll horizontally by 4 pixels}π  FOR i := 1 TO 383 DOπ    SetAddress(i);π  FOR i := 382 DOWNTO 0 DOπ    SetAddress(i);ππ  {scroll vertically by 1 row}π  FOR j := 1 TO 20 DOπ  BEGINπ    FOR i := 1 TO 4 DOπ      SetAddress(i * 80);π    FOR i := 3 DOWNTO 0 DOπ      SetAddress(i * 80)π  END;ππ  ASM {back to 80x25}π    MOV AX,3π    INT 10hπ  END;ππEND.π{π> Your said you could specify how the memory can be layed out by the user,π> but I am in need of what each PORT does. I know you have to sendπ> different values to the port to program it, but I have no idea what eachπ> port reads.ππThere are incredibly much registers to program! For a good overview of most ofπthem, try to get your hands on a copy of VGADOC*.* by Finn Thoegersenπ(jesperf@daimi.aau.dk) which covers programming a lot of SVGA's chipsets, too.ππ                                                          20     05-28-9313:39ALL                      SWAG SUPPORT TEAM        NICEFADE.PAS             IMPORT              14          {πCHRIS BEISELππHey Terje, here's some stuff to get you started on some ideas For theπgroup.  I threw it together it 3 minutes, so it's not much, but theπassembley code isn't bad... here it is:π}ππProgram palette;ππUsesπ  Crt;ππConstπ  vga_segment = $0A000;π  fade_Delay  = 20;ππVarπ  lcv  : Integer;π  temp : Char;ππProcedure video_mode (mode : Byte); Assembler;πAsmπ  mov  AH,00π  mov  AL,modeπ  int  10hπend;ππProcedure set_color (color, red, green, blue : Byte);πbeginπ  port[$3C8] := color;π  port[$3C9] := red;π  port[$3C9] := green;π  port[$3C9] := blue;πend;ππProcedure wait_4_refresh; Assembler;πLabelπ  wait, retr;πAsmπ  mov  DX,3DAhπ wait:  in   AL,DXπ  test AL,08hπ  jz   waitπ retr:  in   AL,DXπ  test AL,08hπ  jnz  retrπend;ππbeginπ  ClrScr;π  Writeln('Hey Terje, this is pretty cheezy, but it does show how to wait');π  Writeln('for the vertical screen refresh in assembley, as well as how to');π  Writeln('change colors, too... this isn''t the palette scrolling, but some');π  Writeln('fade Type routines that may come in handy.  The video mode routine');π  Writeln('was also written in assembley (obviously)... well, next I''m going');π  Writeln('to work on zooming (It could be a cool effect).  C''ya L8r. ');π  Writeln(' Press a key...');π  temp := ReadKey;π  video_mode($13);π  lcv := 0;π  Repeatπ    While lcv < 63 doπ    beginπ      wait_4_refresh;π      set_color(0, lcv, lcv, lcv);π      lcv := lcv + 1;π      Delay(fade_Delay);π    end;π    While lcv > 0 doπ    beginπ      wait_4_refresh;π      set_color(0, lcv, lcv, lcv);π      lcv := lcv - 1;π      Delay(fade_Delay);π    end;π  Until KeyPressed;π  video_mode(3);πend.ππ               21     05-28-9313:39ALL                      SWAG SUPPORT TEAM        PALETTE.PAS              IMPORT              54          { FD>  Hey Greg, do you think you could tell me how to accessπ FD> Mode-X, preferably the source, if it's no trouble.... :)ππnot a problem....  Mostly I do Graphics and stuff With C, but when it all comesπdown to it, whether you use Pascal or C For the outer shell the main Graphicsπroutines are in Assembler (For speed) or use direct hardware port accessπ(again, For speed).πThe following is a demo of using palette scrolling techniques in Mode 13h (X)πto produce a flashy "bouncing bars" effect often seen in demos:π}ππProgram PaletteTricks;π{ Speccy demo in mode 13h (320x200x256) }ππUses Crt;ππConst CGA_CharSet_Seg = $0F000;     { Location of BIOS CGA Character set }π      CGA_CharSet_ofs = $0FA6E;π      CharLength      = 8;          { Each Char is 8x8 bits,  }π      NumChars        = 256;        { and there are 256 Chars }π      VGA_Segment     = $0A000;     { Start of VGA memory     }π      NumCycles       = 200;        { Cycles/lines per screen }π      Radius          = 80;ππ      DispStr         : String =    ' ...THIS IS A LITTLE '+π      'SCROLLY, DESIGNED to TEST SOME GROOVY PASCAL ROUTinES...'+π      '                                                        ';ππ      { Colours For moving bars... Each bar is 15 pixels thick }π      { Three colours are palette entries For RGB values...    }π      Colours : Array [1..15*3] of Byte =π                 (  7,  7, 63,π                   15, 15, 63,π                   23, 23, 63,π                   31, 31, 63,π                   39, 39, 63,π                   47, 47, 63,π                   55, 55, 63,π                   63, 63, 63,π                   55, 55, 63,π                   47, 47, 63,π                   39, 39, 63,π                   31, 31, 63,π                   23, 23, 63,π                   15, 15, 63,π                    7,  7, 63  );πππType  OneChar = Array [1..CharLength] of Byte;ππVar   CharSet:  Array [1..NumChars] of OneChar;π      Locs:     Array [1..NumCycles] of Integer;π      BarLocs:  Array [1..4] of Integer;         { Location of each bar }π      CurrVert,π      Count:    Integer;π      Key:      Char;π      MemPos:   Word;ππProcedure GetChars;π{ Read/copy BIOS Character set into Array }π  Var NumCounter,π      ByteCounter,π      MemCounter:       Integer;π  beginπ      MemCounter:=0;π      For NumCounter:=1 to NumChars doπ        For ByteCounter:=1 to CharLength doπ          beginππCharSet[NumCounter][ByteCounter]:=Mem[CGA_CharSet_Seg:CGA_CharSet_ofs+MemCounter];π            inC(MemCounter);π          end;π  end;πππProcedure VideoMode ( Mode : Byte );π{ Set the video display mode }π  beginπ      Asmπ        MOV  AH,00π        MOV  AL,Modeπ        inT  10hπ      end;π  end;πππProcedure SetColor ( Color, Red, Green, Blue : Byte );π{ Update the colour palette, to define a new colour }π  beginπ      Port[$3C8] := Color;      { Colour number to redefine }π      Port[$3C9] := Red;        { Red value of new colour   }π      Port[$3C9] := Green;      { Green "   "   "    "      }π      Port[$3C9] := Blue;       { Blue  "   "   "    "      }π  end;πππProcedure DispVert ( Var CurrLine : Integer );π  { Display next vertical 'chunk' of the Character onscreen }π  Var Letter:    OneChar;π      VertLine,π      Count:     Integer;π  beginπ      { Calculate pixel position of start of letter: }π      Letter := CharSet[ord(DispStr[(CurrLine div 8)+1])+1];π      VertLine := (CurrLine-1) Mod 8;ππ      { Push the Character, pixel-by-pixel, to the screen: }π      For Count := 1 to 8 doπ        if Letter[Count] and ($80 Shr VertLine) = 0π          then Mem[VGA_Segment:185*320+(Count-1)*320+319] := 0π          else Mem[VGa_Segment:185*320+(Count-1)*320+319] := 181;π  end;ππProcedure CalcLocs;π{ Calculate the location of the top of bars, based on sine curve }π  Var Count:    Integer;π  beginπ      For Count := 1 to NumCycles doπ        Locs[Count] := Round(Radius*Sin((2*Pi/NumCycles)*Count))+Radius+1;π  end;πππProcedure DoCycle;π{  Display the bars on screen, by updating the palette entries toπ   reflect the values from the COLOUR Array, or black For blank lines }ππ  Label Wait,Retr,BarLoop,PrevIsLast,Continue1,Continue2,Rep1,Rep2;ππ  beginπ       Asmπ          { First, wait For start of vertical retrace: }π          MOV   DX,3DAhπWait:     in    AL,DXπ          TEST  AL,08hπ          JZ    WaitπRetr:     in    AL,DXπ          TEST  AL,08hπ          JNZ   Retrππ          { then do bars: }π           MOV   BX,0πBarLoop:π           PUSH  BXπ           MOV   AX,Word PTR BarLocs[BX]π           MOV   BX,AXπ           DEC   BXπ           SHL   BX,1π           MOV   AX,Word PTR Locs[BX]π           PUSH  AXπ           CMP   BX,0π           JE    PrevIsLastπ           DEC   BXπ           DEC   BXπ           MOV   AX,Word PTR Locs[BX]π           JMP   Continue1ππPrevIsLast:π           MOV   AX,Word PTR Locs[(NumCycles-1)*2]ππContinue1:π           MOV   DX,03C8hπ           OUT   DX,ALπ           inC   DXπ           MOV   CX,15*3π           MOV   AL,0πRep1:π           OUT   DX,ALπ           LOOP  Rep1ππ           DEC   DXπ           POP   AXπ           OUT   DX,ALπ           inC   DXπ           MOV   CX,15*3π           xor   BX,BXπRep2:π           MOV   AL,Byte Ptr Colours[BX]π           OUT   DX,ALπ           inC   BXπ           LOOP  Rep2ππ           POP   BXπ           inC   Word PTR BarLocs[BX]π           CMP   Word PTR BarLocs[BX],NumCyclesπ           JNG   Continue2ππ           MOV   Word PTR BarLocs[BX],1πContinue2:π           inC   BXπ           inC   BXπ           CMP   BX,8π           JNE   BarLoopππ        end;π      end;πππbeginππ    VideoMode($13);             { Set video mode 320x200x256 }π    Port[$3C8] := 1;            { Write palette table entry }π    For Count := 1 to 180 do    { Black out the first 180 colours, }π      SetColor(Count,0,0,0);    { one colour will be used per line }ππ    { Now colour each scan line using the given palette colour: }π    MemPos := 0;π    For Count := 1 to 180 doπ      beginπ        FillChar(Mem[VGA_Segment:MemPos],320,Chr(Count));π        MemPos := MemPos + 320;π      end;ππ    SetColor(181,63,63,0);π    CalcLocs;π    For Count := 1 to 4 doπ      BarLocs[Count] := Count*10;ππ    GetChars;π    CurrVert := 1;π    Repeatπ      DoCycle;π      For Count := 1 to 8 doπ        Move(Mem[VGA_Segment:185*320+(Count-1)*320+1],π             Mem[VGA_Segment:185*320+(Count-1)*320],319);π      DispVert(CurrVert);π      inC(CurrVert);π      if CurrVert > Length(DispStr) * 8π        then CurrVert := 1;ππ    Until KeyPressed;   { Repeat Until a key is pressed... }ππ    Key := ReadKey;     { Absorb the key pressed }π    VideoMode(3);       { Reset video mode back to Textmode } end.πend.π                                                                                                              22     05-28-9313:39ALL                      SWAG SUPPORT TEAM        PUTPIXEL.PAS             IMPORT              4           {πMICHAEL NICOLAIππRe: Plotting a pixel.πIn 320x200x256 mode it's very simple:πx : 0 to 319, y : 0 to 199π}ππProcedure Plot(x,y Word; color : Byte);πbeginπ  mem[$A000 : (y * 200 + x)] := color;πend;ππ{You mean mem[$A000:y*320+x]:=color;  don't you? ????? ($UNTESTED)}π                                                                                                                    23     05-28-9313:39ALL                      SWAG SUPPORT TEAM        READLNXY.PAS             IMPORT              20          {πERIC MILLERππ> My question is this: In TP, the outtextxy is supposed to change theπ> CP (current pointer) to the location given in x,y. When you execute aπ> readln after a outtextxy or even and outtext, the program alwaysπ> starts at 0,0.. Is there a way to set the CP where the readln willπ> recognize it?ππ  Here's a demo of a procedure called ReadlnXY; it readsπ  a string in graphics mode using BGI support.π}ππPROGRAM Graphics_Readln;ππUsesπ  Crt, Graph;ππPROCEDURE ReadlnXY(X, Y: Integer; VAR S: String);πVARπ  Ch       : Char;    { key from keyboard }π  Done     : boolean; { our flag for quiting }π  CurColor : word;    { color to write text in }π  OldX     : Integer; { old x }ππBEGINπ  S := '';π  CurColor := GetColor;π  MoveTo(X, Y);π  Done := False;π  WHILE NOT Done  DOπ  BEGINπ    Ch := Readkey;  { get a single key }ππ    CASE Ch ofπ      #0  : { extra key - two chars - let's ignore them }π        Ch := Readkey;ππ      #13 : { return key }π        Done := true; { we got our string, let's go }ππ      #32..#126:  { ASCII 32 (space) through 126 (tilde) }π        BEGINπ          OutText(Ch);π          S := Concat(S, Ch);π        END;ππ      #8  : IF Length(S) > 0 THENπ        BEGINπ          { move back to last character }π          OldX := GetX - TextHeight(S[Length(S)]);π          MoveTo(OldX, GetY);π          { over write last character }π          SetColor(0);π          OutText(S[Length(S)]);π          SetColor(CurColor);π          MoveTo(OldX, GetY);π          { remove last character from the string }π          Delete(S, Length(S), 1);π        END;ππ    END;π  END;πEND; { ReadlnXY }ππππVARπ  GraphMode, GraphDriver: Integer;π  Name, PathToDriver: String;ππBEGINππ  GraphDriver := VGA;            { VGA }π  GraphMode := VGAHi;            { 640x480x16 }π  PathToDriver := 'D:\BP\BGI';   { path to EGAVGA.BGI }π     { you can make this program work with EGA 640x350x16 -π       it  requires 640 wide and 16 colors to work for thisπ       example, but ReadlnXY should work in any graphics mode }π  InitGraph(GraphDriver, GraphMode, PathToDriver); { set graphics mode }ππ  SetTextStyle(DefaultFont, HorizDir, 2);ππ  SetColor(12);ππ  OutTextXY(63, 63, 'Please enter your name: ');π  SetColor(13);π  ReadlnXY(63 ,95, Name);π  CloseGraph;π  Write('The name you entered was: ');π  Writeln(Name);πEND.π                                                                                                           24     05-28-9313:39ALL                      SWAG SUPPORT TEAM        REMAPCGA.PAS             IMPORT              26          {πAfter several tricks to redefine Characters in EGA and VGA in this echo,πhere is one you can use in CGA mode 4,5,6. You will find an Unit, and aπtest Program.π}ππUnit graftabl;ππ{πreleased into the public domainπauthor : Emmanuel ROUSSINπFIDO   : 2:320/200.21πEmail  : roussin@frmug.fr.mugnet.orgππfor using redefined Characters (128 to 255)πin CGA mode 4,5 and 6 Without using GRAFTABL.EXEπ}ππInterfaceππTypeπ  Tcaractere8 = Array [1..8] of Byte;π  Tgraftabl = Array [128..255] of Tcaractere8;ππ{πif you want to use only one font, define it in this Unit, For example :ππConstπ  the_only_font : Tgraftabl = (π                              (x,x,x,x,x,x,x,x),π                              .π                              .π                              (x,x,x,x,x,x,x,x),π                              (x,x,x,x,x,x,x,x)π                              );ππOr you can in your main Program :ππVarπ  my_font : Tgraftabl;ππand define it afterπ}ππVarπ  seg_graftabl,π  ofs_graftabl : Word;ππ{internal Procedures}ππProcedure get_graftabl(Var segment, offset : Word);πProcedure put_graftabl(segment, offset : Word);ππ{Procedures to use in your Programs}ππProcedure init_graftabl;πProcedure use_graftabl(Var aray : Tgraftabl);πProcedure end_graftabl;ππImplementationππProcedure get_graftabl(Var segment, offset : Word);πbeginπ  segment := memw[0 : $1F * 4 + 2];π  offset  := memw[0 : $1f * 4];πend;ππProcedure put_graftabl(segment, offset : Word);πbeginπ  memw[0 : $1f * 4 + 2] := segment;π  memw[0 : $1f * 4] := offsetπend;ππProcedure init_graftabl;π{ interrupt 1F is a Pointer to bitmaps For high 128 Chars (8 Bytes perπ  Character) defined by GRAFTABL.EXE we save this initial Pointer }πbeginπ  get_graftabl(seg_graftabl, ofs_graftabl);πend;ππProcedure use_graftabl(Var aray : Tgraftabl);π{ we define a new Pointer : the address of an Array }πbeginπ  put_graftabl(seg(aray),ofs(aray));πend;ππProcedure end_graftabl;π{ we restore the original Pointer }πbeginπ  put_graftabl(seg_graftabl,ofs_graftabl);πend;ππend.ππProgram test;ππUsesπ  Graph3, Crt, graftabl;πππVarπ  font    : Tgraftabl;π  i,j,tmp : Byte;π  rid     : Char;ππbeginπ  hires;π  init_graftabl;π  fillChar(font,sizeof(font),0);π  use_graftabl(font);ππ  {$F000:$FA6E is the ROM address where the Characters 0 to 127 are defined}ππ  For i := 1 to 26 doπ    For j := 0 to 7 doπ    beginπ      tmp := mem[$F000 : $FA6E + 97 * 8 + (i - 1) * 8 + j] xor $FF;π      tmp := tmp xor $FF;π      tmp := tmp or (tmp div 2);π      font[i + 127, j + 1] := tmp;π      { Char 128 to 153 are redefined }π    end;ππ  For i := 1 to 26 doπ    For j := 0 to 7 doπ    beginπ      tmp := mem[$F000 : $FA6E + 97 * 8 + (i - 1) * 8 + j] or $55;π      font[i + 153, j + 1 ] := tmp;π      { Char 154 to 181 are redefined }π    end;ππ  Writeln('the normal Characters ($61 to $7A) :');π  Writeln;π  For i := $61 to $7A doπ    Write(chr(i));π  Writeln; Writeln;π  Writeln('now, these same Characters, but thick :');π  Writeln;π  For i := 128 to 153 doπ    Write(chr(i));π  Writeln; Writeln;π  Writeln('the same Characters, but greyed :');π  Writeln;π  For i := 154 to 181 doπ    Write(chr(i));π  rid := ReadKey;π  end_graftabl;π  Textmode(co80);πend.ππ                         25     05-28-9313:39ALL                      SWAG SUPPORT TEAM        SETMODE1.PAS             IMPORT              6           {πWell, there are two basic ways of using Graphics mode.π1) Use the BIOS routines to enter this mode.π2) Use the BGI (Borland Graphics Interface) used With the Graph Unitπ   and the appropriate BGI File (as mentioned by you).ππSince you intend to display PCX Files, I guess you have no businessπwith the Graph Unit and the BGI, so I suggest the first way.ππExample:π}ππProgram Enter256;ππUsesπ  Dos;ππVarπ  Regs : Registers;ππbeginπ  Regs.Ah := 0;π  Regs.Al := $13;π  Intr($10, Regs);ππ  Readln;πend.ππ{π  At the end of this Program you will be in 320x200 256 color mode.π}                                                                   26     05-28-9313:39ALL                      SWAG SUPPORT TEAM        SETMODE2.PAS             IMPORT              26          {RV│ok i would like some info on how to remove a tsr added to memory by aπ  │i'd like some info on ext. VGA screens. For examplw i know that inπ  │320x200x256 that one Byte is equal to one pixel. i need this Type ofπ  │info For =< 640x480ππMode $10 (ie 640x350x16)π-------------------------ππIn this mode, the  256K display memory is divided into 4 bit planes ofπ64K each. Each pixel is produced by 4 bits, one from each bit plane, whichπare combined into a 4-bit value that determines which of the 16 colors willπappear on the screen For that pixel.ππThere is a one-to-one correspondense between the bits in each bit plane andπthe pixel on the screen. For example, bit 7 of the first Byte in each bitπplane correspond to the pixel in the upper left-hand corner of the screen.ππThe display memory For the 640x350 Graphics mode is mapped into memory asπa 64K block starting at A000h, With each 64K bit plane occupying the sameπaddress space (ie: in parallel).ππBecause of the one-to-one relationship of bits in bit planes With the pixelsπon the screen, it's straightForward to calculate the address needed toπaccess a particular pixel. There are 640 bits = 80 Bytes per line on theπscreen. Thus the Byte address corresponding to a particular X,Y coordinateπis given by 80*Y + X/8. A desired pixel can then be picked out of the Byteπusing the bit mask register.π}ππProcedure PutPixel(X,Y:Integer; Color:Byte);πVarπ  Byte_address : Word;π  wanted_pixel        : Byte;πbeginπ  Port[$3CE] := 5;        (* mode register *)π  Port[$3CF] := 2;        (* select Write mode 2 *)π  Port[$3CE] := 8;        (* bit mask register *)π                          (* calculate pixel's Byte address *)π  Byte_address := (80 * Y) + (X div 8);π                          (* set the bit we want *)π  wanted_pixel := (1 SHL (7 - (X MOD 8)));π                          (* mask pixel we want *)π  Port[$3CF] := $FF and wanted_pixel;π                          (* turn the pixel we want on *)π  Mem[$A000:Byte_address] := Mem[$A000:Byte_address] or Colorπend; (* PutPixel *)ππFunction ActiveMode : Byte;π  (* Returns the current display mode *)πVarπ  Regs : Registers;     (* Registers from Dos Unit *)πbeginπ  Regs.AH := $0F;       (* get current video mode service *)π  Intr($10,Regs);       (* call bios *)π  ActiveMode := Reg.AL  (* current display mode returns in AL *)πend;ππ{πSome video numbers:ππ  CGA04         = $04;        (* CGA 320x200x4 *)π  CGA06         = $06;        (* CGA 640x200x2 *)ππ  EGA0D         = $0D;        (* 320x200x16,EGA,2 pages (64K), A0000*)π  EGA0E         = $0E;        (* 640x200x16,EGA,4 pages(64K)      " *)π  EGA0F         = $0F;        (* 640x350 B&W,EGA,2 "     "        "  *)π  EGA10         = $10;        (* 640x350x16 EGA,2 "    (128K)     " *)ππ  VGA11         = $11;        (* 640x480x2 B&W VGA, 4 pages (256K) " *)π  VGA12         = $12;        (* 640x480x16  VGA   1 page  (256K) " *)π  VGA13         = $13;        (* 320x200x256 VGA   4 pages (256K) " *)ππExample:ππ  ...π  if (ActiveMode = VGA13) thenπ    beginπ      ....π      ShowPCX256π      ....π    endπ  ...π}π                                                                                                               27     05-28-9313:39ALL                      SWAG SUPPORT TEAM        SETMODE3.PAS             IMPORT              19          {PK>SetVisualPage are Procedures I spent a lot of time investigating withπPK>Really weird results. In fact I locked up Computer several times andππI hate it when that happens <g>.ππPK>then I got frustrated and posted the message hoping there would be someπPK>other way how to go about it. tom Swan's book Mastering Turbo Pascal 6.0ππThere is: Don't use Graph.TPU and Write all your own routines.  In theπfollowing Program, 3 routines SetVidMode, SetPage, and PutPixπillustrate a Graph.TPU-less example of your original requirement.π}ππProgram test0124;πUses Dos;ππConstπ  VidMode = $10;  {..640x350x16 - Supported By VGA and Most EGA }πVarπ  x,y : Integer;π  reg : Registers;ππProcedure SetVidMode(VidMode :Integer);π  beginπ  reg.ah := $00;π  reg.al := VidMode;π  intr($10,reg);π  end;ππProcedure SetPage(Page :Integer);π  beginπ  reg.ah := $05;π  reg.al := page;π  intr($10,reg);π  end;ππProcedure PutPix(Color,Page,x,y : Integer);π  beginπ  reg.ah := $0C;π  reg.al := Color;π  reg.bh := Page;π  reg.cx := x;π  reg.dx := y;π  intr($10,reg);π  end;ππbeginπSetVidMode(VidMode);πSetPage(0);                                {..set active display page }πFor x := 200 to 440 do                     {..use custom PutPix to }π  For y := 100 to 250 do PutPix(3,1,x,y);  {  draw to different page }πWrite(^g);πReadLn;                                    {..press enter to switch }πSetPage(1);                                {  active display page }πReadLn;πend.ππ{πThere are only a few dozen more routines that you need to have theπFunctionality of Graph.TPU - simple stuff like manipulating palettes,πline/circle/polygon algorithms, fill routines, etc., etc....have fun.ππPK>list all video modes and number of pages it is capable of working withπPK>and VGA in 640x480 (that's the mode I have) is supposed to handle onlyπPK>one page. That's is probably the reason why it doesn't work. What isππThat would do it.  From my reference, Advanced MS Dos Programming - RayπDuncan, The best resolution you can get With multiple page support isπ640x350 (Mode $10).ππAbout the ClearViewPort conflict, I experienced similar problems - Iπwent as Far as pixelling out portions of the display to avoid usingπClearViewPort <Sheesh!> - that Graph Unit doesn't make anything easy.π}                                                 28     05-28-9313:39ALL                      SWAG SUPPORT TEAM        SETMODE4.PAS             IMPORT              14          There are basically three ways you can do it, all of them usingπInterrupt 10h (video interrupt). First, set up something in your Varπlike this:ππ  Varπ    Regs : Registers;ππFunction 0 sets the mode, which will also clear the screen.  This isπuseful if you want to set mode and clear screen at the same time.πIt would look like this;ππ  REGS.AH := 0;π  REGS.AL := x; { where x is the mode you want (get a good Dosπ                  reference manual For these) }π  inTR($10,REGS);ππThe other two options are Really inverses of each other...scrollπWindow up and scroll Window down.  The advantage of these is that itπdoesn't clear the border color (set mode does).  The disadvantage isπthere are a lot more parameters to set.  For these, AH = 6 For scroll upπand 7 For scroll down.  AL = 0 (this Forces a clear screen), CH = theπupper row, CL = the left column, DH = the lower row, DL = the rightπcolumn, and BH = the color attribute (Foreground and background).  As Iπsaid, it's a bit more Complicated, but you can set the screen color atπthe same time if you want to (if not, you'll need to get the currentπattribute first and store it in BH).  You'll also have to know theπcurrent screen mode (40 or 80 columns, 25, 35, 43, or 50 lines).ππAs you can see, clearing the screen without using Crt is a bit moreπComplicated, but you can set a lot of options at the same time as well.πIt's up to you.ππJust as an after-note, I'm currently working on a way to useπpage-switching in Crt mode, writing directly to the video memory.  I'mπsick of not being to switch pages without loading Graph (waste of spaceπand memory, just to switch pages).π                            29     05-28-9313:39ALL                      SWAG SUPPORT TEAM        SETMODE5.PAS             IMPORT              19          {CD>     Can someone tell me how to get 320x200x256 screen mode in TurboπCD>Pascal 5.5.ππYes.π}πProgram DemoMode13;πUses Dos,Crt;πVarπ LM : Word;π CD : Word;ππ{π; Enable 320*200*256, return True if successful, otherwise Falseπ;π; Reasons For False return : Already in mode 13, mode 13 unsupported.π}πFunction Enable13:Boolean;π Varπ  Regs : Registers;π beginπ  LM:=LastMode;π  Regs.AH:=$0F;π  intr($10,Regs);π  if Regs.AL<>$13 then beginπ   Regs.AH:=$03;π   intr($10,Regs);π   CD:=Regs.CX;π   Regs.AX:=$0013;π   intr($10,Regs);π   if (Regs.Flags and 1)=0 then beginπ    Enable13:=True;π   end else beginπ    Enable13:=False;π   end;π  end else beginπ   Enable13:=False;π  end;π end;ππ{π; Exit 310*200*256 mode, True if successful, False if notπ;π; Reasons For False return : not in mode 13.π}πFunction Release13:Boolean;π Varπ  Regs : Registers;π beginπ  Regs.AH:=$0F;π  intr($10,Regs);π  if Regs.AL=$13 then beginπ   TextMode(LM);π   Regs.AH:=$01;π   Regs.CX:=CD;π   intr($10,Regs);π   Release13:=True;π  end else beginπ   Release13:=False;π  end;π end;ππ{π; Plot a pixel in 320*200*256 mode.π;π; This may appear quite obvious at first, but take a closer look if you thinkπ; it is Really simple.  if you read your Turbo Pascal book, though, you areπ; required to only ponder the usage of `Absolute' For a moment.π}πProcedure DrawPixel(X,Y:Word;Colour:Byte);π Varπ  Screen : Array [0..319,0..199] of Byte Absolute $A000:$0000;π beginπ  Screen[Y,X]:=Colour;π end;ππ{π; Main Program.  Draws points in four corners in random colours, reads a likeπ; of Text (odd, but it displays it!) then returns to Text mode and quits.π}πbeginπ Writeln;π CheckBreak:=False;π CheckSnow:=False;π DirectVideo:=False;π if Enable13 then beginπ  Randomize;π  DrawPixel(0,0,Random(255));π  DrawPixel(319,0,Random(255));π  DrawPixel(0,199,Random(255));π  DrawPixel(319,199,Random(255));π  GotoXY(1,2);π  Writeln('Type something then press [Enter]');π  readln;π  if (not enable13) then beginπ   ClrScr;π  end else beginπ   Writeln;π   Writeln('Error Exiting mode 13.');π   Writeln('Enter MODE CO80 or MODE MONO to');π   Writeln('restore your screen to Text mode.');π  end;π end else beginπ  Writeln('Error invoking mode 13');π end;π Writeln;πend.π                                                                                    30     05-28-9313:39ALL                      SWAG SUPPORT TEAM        SETMODE6.PAS             IMPORT              9           {πGreat Thanks Chris. Now For another question, This Function would returnπ0..63 For the 256 color palette right? Can I also use this For the 16πcolor VGA & EGA palettes With the exception of it returning a value betweenπ0 and 3? and if you wouldn't mind I could also use another Function thatπwould tell me what video mode I am in. I am examining a Program that can useπvideo modes of CGA4 ($04), CGA2 ($06), EGA ($10), VGA ($12) and MCGA ($13)πand it Uses this Procedure to set the video mode:π}ππProcedure VideoMode (n: Integer);πbeginπ    Reg.ah := $00;π    Reg.al := n;π    intr ($10, Reg);πend;ππ{πWith the N being the hex numbers from the above video modes.ππNow i know next to nothing about interrupts, and your code looks very similarπto what was done to set each color. Is the way to find out the value of al toπcall the interrupt in the same manner as above without specifying a value Forπal? Would it return the current al value...... or am I in left field on thisπone :)π}                                                31     05-28-9313:39ALL                      SWAG SUPPORT TEAM        SETMODE7.PAS             IMPORT              11          I heard (read?) that you wanted to find out how to do 256-colour Graphics.πHere are some Procedures For you.ππUses Dos;   { if your Program doesn't already :) }ππProcedure SetGrMode(grMode : Byte);  { enters a given Graphics mode }π{ does *not* check For presence of VGA -- use With caution!! }πVarπ   r : Registers;πbeginπ     r.AX := grMode;π     Intr($10, R);πend;ππProcedure PutPixel256(p_x, p_y : Integer; p_c : Byte);πbeginπ     Mem[$A000 : p_y * 320 + p_x] := p_c;πend;ππOK, With the SetGrMode Procedure, to enter 256-colour mode, call the Programπwith a value of $13.  So:  SetGrMode($13);πAnd to return to Text mode, call:  SetGrMode($03);πThe second Procedure is self-explanatory, With a few bits of info required.πThe valid co-ords are 0..319 (horizontal) x 0..199 (vertical), so you can't useπGetMaxX or GetMaxY, unless you define them as Constants in the beginning ofπyour Program.  The colour is in the range 0..255.ππ*WARNING*  These Procedure will not work together With a BGI driver or theπGraph Unit.  If you enter Graphics mode With my Procedure, you will not be ableπto output Text, boxes, circles, etc. unless you Write your own Procedures forπthe above.π                                                                                                        32     05-28-9313:39ALL                      SWAG SUPPORT TEAM        SETPAGE.PAS              IMPORT              14          {π Hi..  I am trying to do animation by flipping the two images betweenπ the video pages, but I keep getting lines at the bottom of my screen,π and my screen color changes..  What's up here?π Did you synchronize to the {vertical|horizontal retrace beForeπ flipping? I don't know how to do this, so any helpfull code from you willπ be appreciated. I took this out of my ANIVGA-Unit:ππAt the very beginning of your Program, detect the address of the proper portπ(StatusReg is a global Word Variable):π}ππ Asm  {check whether we are running on a monochrome or color monitor}π   MOV DX,3CCh  {ask Output-register:}π   in AL,DXπ   TEST AL,1    {is it a color monitor?}π   MOV DX,3D4hπ   JNZ @L1      {yes}π   MOV DX,3B4h  {no }π  @L1:          {DX=3B4h/3D4h = CrtAddress-register For monochrome/color}π{ MOV CrtAddress,DX  not needed For this purpose}π   ADD DX,6     {DX=3BAh/3DAh = Status-register For monochrome/color}π   MOV StatusReg,DXπ end; {of Asm}ππ{πLater on, when you want to switch pages:ππ   CLI {time critical routine: do not disturb!}π    mov dx,StatusRegπ  @WaitnotVSyncLoop:π    in   al,dxπ    and  al,8π    jnz  @WaitnotVSyncLoopπ  @WaitVSyncLoop:π    in   al,dxπ    and  al,8π    jz   @WaitVSyncLoopπ{π    HERE! SWITCH PAGES NOW!!! IMMEDIATELY! do not USE BIOS-inTS or OTHERπ    TIME-WASTERS!π}π   STIπ{πWell, that's all there is... if you replace the 2 "and al,8" against "and al,1"πand exchange jnz<->jz, you are syncronizing at the horizontal retrace. But thisπsignal is extremely short (at least Compared With the vertical retr.).π}π                                                                                                                 33     05-28-9313:39ALL                      SWAG SUPPORT TEAM        STARS1.PAS               IMPORT              20          {πBERNIE PALLEKππ> Hmm.. does anyone have an example of a starfield routine in Turbo Pascal..ππOK, here's a sample (I don't know what kind of starfield you're looking for):ππ{EGA/VGA parallax stars}ππUsesπ  Crt, Graph, KasUtils;ππConstπ  starCol : Array[0..2] of Byte = (8, 7, 15);ππTypeπ  StarRec = Recordπ    x : Integer;π    y : Integer;π    d : Integer;  { depth }π  end;ππVarπ  stars : Array[0..31] of StarRec;π  xinc,π  yinc  : Integer;π  ch    : Char;πππProcedure OpenGraph;πVarπ  gd, gm : Integer;πbeginπ  EgaVga_Exe;π  Gd := Detect;π  { this doesn't care if you don't have correct video card or not }π  InitGraph(gd, gm, '');   { put the path to your BGI }πend;ππProcedure InitStars;πVarπ  i : Integer;πbeginπ  For i := 0 to 31 doπ  With stars[i] doπ  beginπ    x := Random(GetMaxX);π    y := Random(GetMaxY);π    d := Random(3);π  end;πend;ππProcedure MoveStars;πVarπ  i : Integer;πbeginπ  For i := 0 to 31 doπ  With stars[i] doπ  beginπ    PutPixel(x, y, 0);π    x := x + xinc * (d + 1);π    if (x < 0) thenπ      x := x + GetMaxX;π    if (x > GetMaxX) thenπ      x := x - GetMaxX;π    y := y + yinc * (d + 1);π    if (y < 0) thenπ      y := y + GetMaxY;π    if (y > GetMaxY) thenπ      y := y - GetMaxY;π    PutPixel(x, y, starCol[d]);π  end;πend;ππbeginπ  OpenGraph;  (* enter Graphics mode *)π  InitStars;π  xinc := 1;π  yinc := 0;π  Repeatπ    MoveStars;π    Delay(10);π    (* Delay here For faster computers *)π  Until KeyPressed;π  ch := ReadKey;π  if (ch = #0) thenπ    ch := ReadKey;  (* get rid of extended keycodes *)π  CloseGraph;πend.ππ{πWhew!  There you have it!  Untested, of course, so you may have to iron out aπfew bugs.ππ**** BIG HINT: You should probably use Real numbers instead of Integer numbersπfor x and y positions and increments, and Round them when PutPixel-ing!  Thisπwill allow you to make smoother transitions, as well as bouncing effects, andπother neat stuff. ****ππYou'll notice (if the thing works) that the stars move horizontally only, andπthe dimmer ones move slower than the bright ones (parallax/multi-layered).  Youπcan add extra layers, but remember to change the StarCol Constant so you haveπthe right number of colours For the stars.ππSorry, I was too lazy to comment it thoroughly; I'm expecting that you'll beπable to figure it out Without too much trouble.  Sorry if you can't; Write meπfor an explanation.  TTYL.π}π                                                           34     05-28-9313:39ALL                      SWAG SUPPORT TEAM        STARS2.PAS               IMPORT              11          { DANIEL SCHLENZIG }ππProgram stars;ππConstπ  maxstars = 200;ππVarπ  star  : Array[0..maxstars] of Word;π  speed : Array[0..maxstars] of Byte;π  i     : Word;ππProcedure create;πbeginπ  For i := 0 to maxstars doπ  beginπ    star[i]  := random(320) + random(200) * 320;π    speed[i] := random(3) + 1;π    if mem[$a000 : star[i]] = 0 thenπ      mem[$a000 : star[i]] := 100;π  end;πend;ππProcedure moveit; Assembler;πAsmπ  xor   bp,bpπ  mov   ax,0a000hπ  mov   es,axπ  lea   bx,starπ  lea   si,speedπ  mov   cx,320ππ @l1:π  mov   di,[bx]π  mov   al,es:[di]π  cmp   al,100π  jne   @j1π  xor   al,alπ  stosbπ @j1:π  mov   al,[si]π  xor   ah,ahπ  add   [bx],axπ  mov   ax,bxπ  xor   dx,dxπ  div   cxπ  mul   cxπ  mov   dx,bxπ  sub   dx,axπ  cmp   dx,319π  jle   @j3π  sub   [bx],cxπ @j3:π  mov   di,[bx]π  mov   al,es:[di]π  or    al,alπ  jnz   @j2π  mov   al,100π  stosbπ @j2:π  add   bx,2π  inc   siπ  inc   bpπ  cmp   bp,maxstarsπ  jle   @l1π end;ππbeginπ  Asmπ    mov   ax,13hπ    int   10hπ    call  createππ   @l1:π    mov   dx,3dahπ   @r1:π    in    al,dxπ    test  al,8π    je    @r1ππ    call moveitπ    in   al,60hπ    cmp  al,1π    jne  @l1;π  end;πend.π                                                                                                                         35     05-28-9313:39ALL                      SWAG SUPPORT TEAM        TEXTFADE.PAS             IMPORT              34          {πI attempted to Write a Unit For Text FADING, but I don't have it all downπright...  If any one wants to play With the Unit and perfect it I would notπmind!  My problem is that I do not know the correct values to change in theπcolor register For the affect of a fade.  Once all the values are 0 the screenπis black, but on the way there the screen gets some strange colors... Also, ifπyou know how to change the colors, you can implement your own custom colors forπText mode.  I think 256 different colors, but only 16 at a time. (I am onlyπguessing at that last part).   The FADEOUT and FADEIN does work here, but itπgoes through some strange colors on the way!ππRobertπ}ππUnit TextFade; {attempt For implementing Text fading}π{ only works For VGA or SVGA as Far as I know! }ππInterfaceππUses Dos, Crt;ππTypeπ  ColorRegister =π  Recordπ    Red      : Byte;π    Green    : Byte;π    Blue     : Byte;π  end;ππ  ColorRegisterArray    = Array[0..255] of ColorRegister;π  ColorRegisterArrayPtr = ^ColorRegisterArray;ππVarπ  SaveCRAp      : ColorRegisterArrayPtr;ππProcedure SaveColorRegister(Var CRAp : ColorRegisterArrayPtr);π{ given a color register Array ptr, this will save the current }π{ values so you can restore from them later...                 }ππProcedure SetColorRegister(Var CRAp : ColorRegisterArrayPtr);π{ when you adjust the values of a color register set, this     }π{ Procedure will make put the new values into memory           }ππProcedure FadeOut(MS_Delay : Integer);π{ using the global Variable 'SaveCRAp', this will fade the Text}π{ screen out till all the values in the color register Array   }π{ ptr are 0                                                    }ππProcedure FadeIn(MS_Delay : Integer);π{ once again using the global Variable 'SaveCRAp', this will   }π{ fade the screen back in till all values of the current color }π{ register Array ptr are equal to 'SaveCRAp'                   }ππImplementationππProcedure Abort(Msg : String);πbeginπ  Writeln(Msg);π  Halt(1);πend;ππProcedure SaveColorRegister(Var CRAp : ColorRegisterArrayPtr);πVarπ  R : Registers;πbeginπ  With R Doπ  beginπ    ah := $10;π    al := $17;π    bx := $00;π    cx := 256;π    es := Seg(crap^);π    dx := Ofs(crap^);π  end;π  Intr($10,r);πend;ππProcedure SetColorRegister(Var CRAp : ColorREgisterArrayPtr);πVarπ  R : Registers;πbeginπ  With R Doπ  beginπ    ah := $10;π    al := $12;π    bx := $00;π    cx := 256;π    es := Seg(crap^);π    dx := Ofs(crap^);π  end;π  Intr($10,r);πend;ππProcedure FadeOut(MS_Delay : Integer);πVarπ  NewCRAp : ColorRegisterArrayPtr;π  W       : Word;π  T       : Word;πbeginπ  New(NewCRAp);π  If NewCRAp = NIL Thenπ    Abort('Not Enough Memory');π  NewCrap^ := SaveCrap^;π  For T := 1 to 63 Doπ  beginπ    For W := 0 to 255 Doπ    With NewCRAp^[w] Doπ    If Red + Green + Blue > 0 Thenπ    beginπ      Dec(Red);π      Dec(Green);π      Dec(Blue);π    end;π    SetColorRegister(NewCRAp);π    Delay(MS_Delay);π  end;πend;ππProcedure FadeIn(MS_Delay : Integer);πVarπ  NewCRAp : ColorRegisterArrayPtr;π  W       : Word;π  T       : Word;πbeginπ  New(NewCRAp);π  If NewCRAp = Nil Thenπ    Abort('Not Enough Memory');π  FillChar(NewCRAp^,SizeOf(NewCRAp^),0);π  For T := 1 to 63 Doπ  { The values in the color register are not higher than 63 }π  beginπ    For W := 0 to 255 Doπ    If SaveCRAp^[w].Red + SaveCRAp^[w].Green + SaveCRAp^[w].Red > 0 Thenπ    beginπ      If NewCRAp^[w].Red   < SaveCRAp^[w].Red Thenπ        Inc(NewCRAp^[w].Red);π      If NewCRAp^[w].Green < SaveCRAp^[w].Green Thenπ        Inc(NewCRAp^[w].Green);π      If NewCRAp^[w].Blue  < SaveCRAp^[w].Blue Thenπ        Inc(NewCRAp^[w].Blue);π    end;π    SetColorRegister(NewCRAp);π    Delay(MS_Delay);π  end;πend;πππbeginπ  New(SaveCRAp);π  {get memory For the Pointer}π  If SaveCRAp = Nil Then Abort('Not Enough Memory');π  {make sure it actually got some memory}π  SaveColorRegister(SaveCRAp);π  {save the current values into SaveCRAp}πend.ππ---------------8<-----cut here------>8---------ππHere is a demo of how to use it...πππUses TextFADE;ππbeginπ   FADEOUT(10);π   WriteLN(' HOW DOES THIS LOOK');π   FADEIN(10);π   Dispose(SaveCRAp);π   {I just Realized I never got rid of this Pointer before!}πend.π                          36     05-28-9313:39ALL                      SWAG SUPPORT TEAM        TRICKS.PAS               IMPORT              19          {πSorry it took so long - anyway here's a new batch of VGA TRICKS :πFirst there's your basic equipment - synchronizing withπthe vertical Crt retrace.π( You can use this For hardware VGA scrolling synchronisation too, justπsubstitute the Delay(14) in my old routine For a call to thisπProcedure.)π}ππProcedure VRET;Assembler; {works For CGA,EGA and VGA cards}πAsmπ  MOV  DX, $03DAπ  MOV  AH, 8π@Wau: in   AL, DXπ  TEST AL, AHπ  JNZ  @Wau     { wait Until out of retrace }π@Wai: in   AL, DXπ  TEST AL, AHπ  JZ   @Wai     { wait Until inside retrace }πendππ{πThe following is Really new, as Far as I know: breaking the colorπbarrier by displaying more than 64 different colors on a Text modeπscreen. (But it will work For Text and Graphics color modes.)πIt displays the effect For approximately SEC seconds, affectingπthe black background and any black Characters. note that ifπyou have the border set to black too, the bars will expand into it.π}ππProcedure ColorBars(Sec:Byte);Assembler;πAsmπ  MOV AL,Secπ  MOV AH,70      { assume a 70 Hz mode (= 400 lines like mode 3 or $13)}π  MUL AHπ  MOV CX,AXπ  MOV DX,$03DAπ  in AL,DXπ  MOV DX,$03C0   { assume color nr 0 = default Text background.. }π  MOV AL,$20+0   { set color nr 0 .. }π  OUT DX,ALπ  MOV AL,0       { .. to DAC color 0 }π  OUT DX,ALπ@Doscreen:π  xor SI,SIπ  CLIπ  MOV DX,$03DAπ  MOV AH,8π@Wau: in AL,DXπ  TEST AL,AHπ  JNZ @Wau       { wait Until out of retrace }π@Wai: in AL,DXπ  TEST AL,AHπ  JZ @Wai        { wait Until inside retrace }π@Doline:π  STIπ  MOV DX,$03C8  { point to DAC[0] }π  MOV AL,0π  OUT DX,ALπ  inC SI        { line counter }π  MOV BX,SIπ  ADD BX,CX     { prepare For color effect }π  MOV DI,$03C9π  CLIπ  MOV DX,$03DAπ@Whu: in AL,DXπ  RCR AL,1π  JC @Whu       { wait Until out of horizontal retrace }π@Whi: in AL,DXπ  RCR AL,1π  JNC @Whi      { wait Until inside retrace }π  MOV DX,DIπ  XCHG BX,AX  { tinker With these to change the chromatic effect}π  OUT DX,AL   { dynamic Red }π  ADD AL,ALπ  OUT DX,AL   { dynamic Green }π  XCHG SI,AXπ  OUT DX,AL   { static Blue }π  XCHG SI,AXπ  CMP SI,200    { paint 200 lines }π  JBE  @dolineπ  DEC DX         { last line }π  MOV AL,0       { reset to black For remainder of screen }π  OUT DX,ALπ  inC DXπ  OUT DX,ALπ  OUT DX,ALπ  OUT DX,ALπ  STIπLoop @Doscreenπend;ππ                 37     05-28-9313:39ALL                      SWAG SUPPORT TEAM        TWEAKED.PAS              IMPORT              32          {π Hi, would anyone like to tell me how to get the tweaked videoπ mode With 4 pages to work With because I'm tired of the 16 colorπ 2 page demos I'm making.ππSure, here's an adaptation of some code from Dr. Dobbs magazine on Mode-X.πI've only posted the routine to set the VGA to 360x240x256 With 3 pages ofπGraphics.  Only 3 pages since the increase in resolution Uses more RAM.π}ππProcedure InitVGA360x240;ππConstπ  GC_inDEX    = $03CE;    { VGA Graphics Controller }π  SC_inDEX    = $03C4;    { VGA Sequence controller }π  CrtC_inDEX  = $03D4;    { VGA Crt Controller      }π  MISC_OUTPUT = $03C2;    { VGA Misc Register       }π  MAP_MASK    = $02;      { Map Register #          }π  READ_MAP    = $04;      { Read Map Register #     }ππ  VMODE_DATA  : Array[1..17] of Word =π                   ($6B00,    { Horizontal total          }π                    $5901,    { Horizontal displayed      }π                    $5A02,    { Start horizontal blanking }π                    $8E03,    { end horizontal blanking   }π                    $5E04,    { Start H sync.             }π                    $8A05,    { end H sync.               }π                    $0D06,    { Vertical total            }π                    $3E07,    { Overflow                  }π                    $4109,    { Cell height               }π                    $EA10,    { V sync. start             }π                    $AC11,    { V sync. end/Prot CR0 CR7  }π                    $DF12,    { Vertical displayed        }π                    $2D13,    { offset                    }π                    $0014,    { DWord mode off            }π                    $E715,    { V Blank start             }π                    $0616,    { V Blank end               }π                    $E317);   { Turn on Byte mode         }ππbeginπ  Asmπ   mov   ax, $13π   int   $10ππ   mov   dx, SC_inDEX           { Sequencer Register }π   mov   ax, $0604              { Disable Chain 4 Mode }π   out   dx, axππ   mov   ax, $0100              { (A)synchronous Reset }π   out   dx, axππ   mov   dx, MISC_OUTPUT        { VGA Misc Register }π   mov   al, $E7                { Use 28Mhz Clock & 60Hz }π   out   dx, alππ   mov   dx, SC_inDEX           { Sequencer Register }π   mov   ax, $0300              { Restart Sequencer }π   out   dx, axππ   {π     Diasable Write protect For CrtC Registers 0-7, since we areπ     about to change the horizontal & vertical timing settings.π   }π   mov   dx, CrtC_inDEX         { VGA CrtC Registers }π   mov   al, $11                { CrtC register 11h }π   out   dx, al                 { Load current value }π   inc   dx                     { Point to data }π   in    al, dx                 { Get CrtC register 11h }π   and   al, $7F                { Mask out Write protect }π   out   dx, al                 { and send it back }ππ   { Send CrtC data in VMODE_DATA Array to the CrtC. }π   mov   dx, CrtC_inDEX         { VGA CrtC Registers }π   cld                          { Forward block load }π   mov   si, offset VMODE_DATA  { Get parameter data }π   mov   cx, 17                 { Number of entries in block }ππ   @@1:π     mov   ax, ds:[si]      { Get next parameter value }π     inc   si               { Advance to next Word }π     inc   siπ     out   dx, ax           { Output next value }π     loop  @@1              { Process next value }ππ   { Clear all VGA memory to black. }π   mov   dx, SC_inDEX     { Select all planes }π   mov   ax, $0F02π   out   dx, axππ   mov   ax, VGA_SEG      { Point to VGA memory }π   mov   es, axπ   mov   di, 0ππ   xor   ax, ax           { clear 256K }π   mov   cx, $8000        { 32K * 2 * 4 planes }π   rep   stoswπ  end;πend;π{πThat's about it.  The video memory in this mode is organised a bit differentlyπthan CGA/HERC.  It is a lot like the 16 color modes you're probably used to, inπthat you must go through the EGA/VGA Registers to access the memory, by settingπMAP MASK & PLANE SELECT, etc.π}π                             38     05-28-9313:39ALL                      SWAG SUPPORT TEAM        TXTFADE.PAS              IMPORT              13          { RON CZARNIK }ππUnit TXTFADE;ππInterfaceππProcedure TextFadeIn(Speed : Integer);πProcedure TextFadeOut(Speed : Integer);ππImplementationπUsesπ  Dos, Crt;ππTypeπ  DacType = Array[1..256,1..3] of Byte;ππVarπ  dac1,π  dac2   : DacType;π  x, y,π  i, erg,π  gesamt : Word;πππProcedure Read_DACs(Var Dac : DacType);πVarπ  r : Registers;πbeginπ  r.ax := $1017;π  r.bx := 0;π  r.cx := 256;π  r.es := SEG(Dac);π  r.dx := Ofs(Dac);π  Intr($10, r);πend;ππProcedure Write_DACs(Dac : DacType);πVarπ  r : Registers;πbeginπ r.ax := $1012;π r.bx := 0;π r.cx := 256;π r.es := seg(Dac);π r.dx := Ofs(Dac);π Intr($10, r);πend;ππ{ fade....}πProcedure TextFadeOut(Speed : Integer);πbegin;π  Repeatπ    erg := 0;π    For x := 1 to 256 doπ      For y := 1 to 3 doπ      beginπ        if dac2[x, y] > 0 thenπ          DEC(dac2[x, y]);π        erg := erg + dac2[x, y];π      end;π    Write_Dacs(dac2);π    Delay(Speed);π  Until erg = 0;πend;ππ{ restore....fades also}πProcedure TextFadeIn(Speed : Integer);πbegin;π  Repeatπ    erg := 0;π    For x := 1 to 256 doπ      For y := 1 to 3 doπ      beginπ       if dac2[x, y] < dac1[x, y] thenπ         INC(dac2[x,y]);π       erg := erg + dac2[x, y];π      end;π    Write_Dacs(dac2);π    Delay(Speed);π  Until (erg = gesamt) or (KeyPressed);π  Write_Dacs(dac1);πend;ππbeginπ  Read_Dacs(dac1);π  dac2 := dac1;π  gesamt := 0;π  For x := 1 to 256 doπ    For y := 1 to 3 doπ      gesamt := gesamt + dac1[x, y];ππend.π                                                                                                       39     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGA-PTR.PAS              IMPORT              19          {    Make a Pointer, make a Type of the data Type you are dealing with, make asπmany Pointers as you will need data segments (or as commonly practiced amongstπthe Programming elite, make an linked list of the data items), and call theπGETMEM Procedure using the Pointer in the Array... Here is an example I use toπcopy VGA (320x200x256) screens...π}ππTypeπ    ScreenSaveType = Array[0..TheSize] of Byte;πVarπ   TheScreen                    : ScreenSaveType Absolute $A000:0000;π   Screen                       : Array[1..100] of ^ScreenSaveType;ππbeginπ     InitGraphics;π     Count := 0;ππ     Repeatπ           Count := Count + 1;π           GetMem(Screen[Count],Sizeof(ScreenSaveType));π           WriteLn('Memory at Screen ',Count,' : ',MemAvail); {THIS MAKESπ                                                               THE PAGES}π     Until MemAvail < 70000;π     For X := 1 to Count doπ         For A := 1 to TheSize do                   {THE MAKES A SCREEN}π             Screen[X]^[A] := Random(255);π     E := C;π     X := 0;π     GetTime(A,B,C,D);π     C2 := 0;ππ     Repeatπ           X := X + 1;π           GetTime(A,B,C,D);π           if C <> E thenπ              beginπ              C2 := C2 + 1;π              testresults[C2] := X;π              X := 1;π              E := C;π              end;π     TheScreen := Screen[X mod Count + 1]^;π     Move(Scroll2,Scroll1,Sizeof(Scroll2));π     Until KeyPressed;π     WriteLn(Test,'Number of Screens :',Count);π     For X := 1 to C2 doπ         WriteLn(Test,'Number of flips, second #',X,':',testresults[x]);π     Close(Test);πend.ππ{    I didn't try and Compile that, I also edited out the ProcedureπinitGraphics because you aren't Really interested in that end. However whereπit says "THIS MAKES THE PAGES" is what you want to do.. In this particularπversion I made 4 Graphics pages under pascal and 5 outside of pascal, I couldπhave fit more but I have too many TSRS. Using Extended memory I can fit aboutπ20 Graphics pages (I got about 2 megs ram), but you can extend that as Far asπram may go. The MOVE command isn't a bad command either to know. I got whenπrunning a Text mode, 213 Text pages per second. I was even impressed (PSπGraphics people, I got 16 Graphics pages per second in 320x200x256 mode!)...π}π                             40     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGA256EX.PAS             IMPORT              10          (*πERIC MILLERππ> Let's suppose that I used VGA256.BGI.  I change it to VGA256.OBJ.  And inπ> my program, I type the following: {$L VGA256.OBJ}ππWell, you can't lin VGA256.BGI into the program that way; for someπreason, if it wasn't included in TP6 it won't register.  You haveπto use the InstallUserDriver function instead of RegisterBGIDriver.πHere is a program that get's into VGA256 mode that way - but ofπcourse you must already know how to do it.π*)ππPROGRAM Vg;ππUsesπ  Graph;ππFUNCTION vgaPresent : boolean; assembler;πasmπ  mov ah,$Fπ  int $10π  mov ax,$1A00π  int $10      {check for VGA/MCGA}π  cmp al,$1Aπ  jne @ERR     {no VGA Bios}π  cmp bl,7π  jb @ERR      {is VGA or better?}π  cmp bl,$FFπ  jnz @OKπ @ERR:π  xor al,alπ  jmp @EXITπ @OK:π  mov al,1π @EXIT:πend;ππ{$F+}πFUNCTION DetectVGA256: Integer;πBEGINπ  IF vgaPresent THENπ    DetectVGA256 := 0π  ELSEπ    DetectVGA256 := grError;πEND;π{$F-}πππVARπ  VGA256: Integer;π  B: Integer;ππBEGINπ  VGA256 := InstallUserDriver('VGA256', @DetectVGA256);π  B := 0;π  InitGraph(VGA256, B, '');π  OutText('In 320x200x256 - press enter');π  Readln;π  CloseGraph;πEND.π                             41     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGADETC1.PAS             IMPORT              7           {πSEAN PALMERππWell, here are routines to detect a VGA and an EGA adapter...π}πUsesπ  Crt;ππVarπ  OldMode : Byte;ππfunction EGAInstalled : boolean; assembler;πasmπ  mov ax, $1200π  mov bx, $10π  mov cx, $FFFFπ  int $10π  inc cxπ  mov al, clπ  or  al, chπend;ππfunction VgaPresent : boolean; assembler;πasmπ  mov ah, $Fπ  int $10π  mov oldMode, al   {save old Gr mode}π  mov ax, $1A00π  int $10           {check for VGA/MCGA}π  cmp al, $1Aπ  jne @ERR          {no VGA Bios}π  cmp bl, 7π  jb  @ERR          {is VGA or better?}π  cmp bl, $FFπ  jnz @OKπ @ERR:π  xor al, alπ  jmp @EXITπ @OK:π  mov al, 1π @EXIT:πend;ππbeginπ  OldMode := LastMode;π  Writeln(EGAInstalled);π  Writeln(VGAPresent);πend.                                                                          42     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGADETC2.PAS             IMPORT              8           {π> I know how to determine the current mode of a card, but how do a lot ofπ> Programs determine if a VGA is present in the first place? I'd ReallyππMICHAEL NICOLAIπIt's very easy to check if a VGA card is present, 'cause there are someπFunctions which are only supported on VGAs. The best one is this:π}ππUsesπ  Dos;ππFunction Is_VGA_present : Boolean;πVarπ regs : Registers;πbeginπ Is_VGA_present := True;π regs.ax := $1A00;π intr($10, regs);π if (regs.al <> $1A) thenπ  Is_VGA_present := False;πend;πππ{ KELD R. HANSEN }ππFunction VGA : Boolean; Assembler;πAsmπ  MOV     AH,1Ahπ  INT     10hπ  CMP     AL,1Ahπ  MOV     AL,Trueπ  JE      @OUTπ  DEC     AXπ @OUT:πend;ππ{ will return True if a VGA card is installed. }πbeginπ  Writeln(Is_VGA_present);π  Writeln(VGA);πend.                                                                                                                           43     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGAFILE.PAS              IMPORT              21          {π  Sean Palmerππ> Does anyone know of any way to display a single screen of Graphics onπ> EGA 640x350 mode *quickly*.  It can be VGA as well; I'm just trying toπ> display the screen *fast* from a disk File.  I know, I could have usedπ> the GIF or PCX format (or any other format), but I want to make aπ> proprietary format to deter hacking of the picture.  So, what I want toπ> know is how to read the data from disk directly to screen.  I'veπ> figured out that BlockRead (if I can get it to work) is the best methodπ> of reading the data from the disk, but I don't know of any fast, and Iπ> mean *fast*, methods of writing the data to the screen.  Would it beπ> feasible to use an Array the size of the screen and Move the Array toπ> the screen (I'd need memory locations For that, if possible)?  Anyπ> response (ideas, solutions, code fragments) would be appreciated.ππYou could set up the screen as an Absolute Variable.πThen read in each plane as an Array DIRECTLY from the disk File.πBefore reading each plane, set up Write mode 0 (should be already in mode 0)πand make sure that the enable set/reset register is set to 0 so that the cpuπWrites go directly to the planes. Set the sequencer map mask register forπeach plane so you only Write to them one at a time. and enable the entire BitπMask register ($0F). Then after telling it which plane, read directly fromπthe File. No I haven't tested the following code and most of it's gonna beπfrom memory but give it a try:ππthe File:π  Plane 0π  Plane 1π  Plane 2π  Plane 3ππeach Plane:π  350 rows of 80 Bytes (each bit belongs to a different pixel)π}ππTypeπ  scrRec = Array[0..640 * 350 div 8 - 1] of Byte;πVarπ  screen : scrRec Absolute $A000 : 0000;π  dFile  : File of scrRec;ππConstπ  gcPort  = $3CE;  {EGA/VGA Graphics controller port}π  seqPort = $3C4;  {EGA/VGA sequencer port}ππProcedure readFileToMode10h(s:String);πVarπ  dFile : File of scrRec;π  i     : Byte;πbeginπ  Asmπ    mov ax, $10;π    int $10;π  end;  {set up video mode}π  assign (dFile,s);π  reset(s);  {no error checking 8) }π  portw[gcPort] := $0001;    {clear enable set/reset reg}π  portw[gcPort] := $FF08;    {set entire bit mask (this is the default?)}π  For i := 0 to 3 doπ  beginπ   {set map mask reg to correct plane}π   portw[seqPort] := (1 shl (i + 8)) + $02;π   read(dFile, screen); {load that plane in}π  end;π  portw[seqPort] := $0F02;   {restore stuff to normal}π  portw[gcPort]  := $0F01;π  close(dFile);πend;π                                                                                                             44     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGAFONTS.PAS             IMPORT              22          {π>so it appears nothing happened).  I have seen some Programs that areπ>able to save the Dos font into a buffer in the Program and then justπ>set the video card back to that font when the Program quits.  The problemπ>is, I have not seen any documented Dos interrupt that will allow me toπ>do this.π>  I'm wondering if anyone knows of such an interrupt that I can use toπ>  get the current VGA font and save it to a buffer.π>  Any help would be greatly appreciated!ππ   Interrupt $10 is what you're looking For. Function $11,π   subFunction $30 gets the Character generator info.π   Function $11, subFunction $10 loads user fonts. Function $11 canπ   also be used to Reset to one of the hardware fonts (subFunctionπ   $11 Resets to ROM 8x14, $12 Resets to ROM 8x8, $14 Resets to VGAπ   ROM 8x16)ππ   The structure Types are as follows:π}πTypeππ  { enumerated font Type }π  ROMfont = (ROM8x14, ROM8x8, ROM8x16);ππ  { Character definition table }π  CharDefTable = Array[0..4096] of Byte;π  CharDefPtr   = ^CharDefTable;ππ  { Text Character generator table }π  Char_Table = Recordπ     Points :Byte;π     Def    :CharDefPtr;π  end;ππ  { font Format }π  FontPackage = Recordπ     FontInfo :Char_Table;π     Ch       :CharDefTable;π  end;π  FontPkgPtr = ^FontPackage;ππ{ Here are some handy Procedures to use those Types: }ππProcedure GetCharGenInfo(font: ROMfont; Var Table:Char_Table);πbeginπ  if is_EGA thenπ  beginπ    Reg.AH := $11;π    Reg.AL := $30;π    Case font ofπ      ROM8x8 : Reg.BH := 3;π      ROM8x14: Reg.BH := 2;π      ROM8x16: Reg.BH := 6;π    end;π    Intr($10, Reg);π    Table.Def := Ptr(Reg.ES, Reg.BP);π    Case font ofπ      ROM8x8 : Table.Points := 8;π      ROM8x14: Table.Points := 14;π      ROM8x16: Table.Points := 16;π    end;π  end;πend;ππProcedure SetHardwareFont(Var font :ROMfont);πbeginπ  if is_EGA thenπ  beginπ    Reg,AH := $11;π    Case font ofπ      ROM8x14 : Reg.AL := $11;π      ROM8x8  : Reg.AL := $12;π      ROM8x16 :π        if is_VGA thenπ           Reg.AL := $14 { 8x16 on VGA only }π        elseπ        beginπ           Reg.AL := $12;π           font := ROM8x14;π        end;π    end;π    Reg.BL := 0;π    Intr($10, Reg);π  end;πend;ππFunction FetchHardwareFont(font :ROMfont):FontPkgPtr;πVarπ  pkg :FontPkgPtr;πbeginπ  New(pkg);π  GetCharGenInfo(font, Pkg^.FontInfo);π  Pkg^.Ch := Pkg^.FontInfo.Def^;π  FetchHardwareFont := Pkg;πend;ππProcedure LoadUserFont(pkg :FontPkgPtr);πbeginπ  Reg.AH := $11;π  Reg.AL := $10;π  Reg.ES := Seg(pkg^.ch);π  Reg.BP := Ofs(pkg^.ch);π  Reg.BH := Pkg^.FontInfo.Points;π  Reg.BL := 0;π  Reg.CX := 256;π  Reg.DX := 0;π  Intr($10, Reg);πend;ππ                                                                         45     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGASCRL1.PAS             IMPORT              20           {π Anivga is the best set of Graphics routines i've seen For the PC sinceπ i stopped using my old 4,7 Mhz MSX (which had smooth sprites &π scrolling) and the one With the most extra's.ππWell, here is >ONE< solution For you.  It is one I have used in aπstreetfighter Type game a friend and I have been working on (the friendπis an artist who has been doing the pics While I'm doing the software).πIt turns out, using an index-to-index copy during vertical retrace isπfast enough to get at least (and I mean at LEAST--I've been able to overπDouble this rate) 18.2 frames per second on a 16bit VGA card.ππThe code (in pascal, although the Program itself is written in C++, theπtheory works With TP6.0) would look something like this:π}ππTypeπ  ScreenRec = Array[0..63999] of Byte;π  ScreenPtr = ^ScreenRec;ππVarπ  VGAScreen : ScreenRec Absolute $A000:$0000; {I think thats how you doπ                                               it, been a While since Iπ                                               had to do things this way}ππProcedure VS_PutPixel(x, y: Integer; c:Byte; VS: ScreenPtr);ππbeginπ  VS^[(y*320)+x] := c; {Again, this may be off slightly--my originalπ                        pascal Implementation used a member Variable inπ                        an Object}πend;ππProcedure VS_Write(VS: ScreenPtr);ππVarπ  X : Integer;π  Y : Integer;ππbeginπ  {Wait For a retrace--see a VGA manual For how to do this, it takesπ  monitoring two ports.  if you are already in a retrace, wait For it toπ  end and another one to begin}π  For Y := 0 to 199 doπ    For X := 0 to 319 doπ      VGAScreen[(Y*320)+X] := VS^[(Y*320)+X];πend;ππ{πWith this method, you even have time in the nexted For loops (!) to do aπComparison.  One I typically use (For emulating multiple planes) is ifπVS^[(Y*320)+X] <> 0...  That lets me copy multiple screens.  to give youπan idea of how fast this is, on my 386/25, I can do this during a timerπinterrupt (18.2 times a second) without any problems, and still haveπtime to do full collision detection and multisprite animation withπscrolling backgrounds and Soundblaster Sound.  During the retraceπperiod, you can move quite a bit of inFormation into the VGA card,πbecause memory accesses are MUCH faster (the screen is also not beingπupdated).  This is CompLETELY flicker free using this technique (ifπsmaller sections are chaging, you MIGHT consider only copying parts ofπthe screen).ππ}                  46     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGASCRL2.PAS             IMPORT              14          {   The following Turbo Pascal Program displays HARDWARE SCROLLinGπ   For 100% Compatible VGA cards,in mode $13.π   I'd be grateful if anyone interestedπ   could test this and report the results :π}ππProgram VGASLIDE; {requirements TP6 or higher + register-Compatible VGAπ}ππUses Crt;ππVarπ  t,slide:Word;π  ch:Char;ππProcedure VgaBase(Xscroll,Yscroll:Integer);π  Var dum:Byte;π beginπ  Dec(SLIDE,(Xscroll+320*Yscroll));   { slide scrolling state         }π  Port[$03d4]:=13;                    { LO register of VGAMEM offset  }π  Port[$03d5]:=(SLIDE shr 2) and $FF; { use 8 bits:  [9..2]           }π  Port[$03d4]:=12;                    { HI register of VGAMEM offset  }π  Port[$03d5]:= SLIDE shr 10;         { use 6 bits   [16..10]         }π  Dum:=Port[$03DA];                   { reset to input by dummy read  }π  Port[$03C0]:=$20 or $13;            { smooth pan = register $13     }π  Port[$03C0]:=(SLIDE and 3) Shl 1;   { use bits [1..0], make it 0-2-4-6π}π end;πππbegin {main}ππ  Asm                {inITIALIZE vga mode $13 using BIOS}π  MOV AX,00013hπ  inT 010hπ  end;ππ  SLIDE:=0;ππ  { draw a quick test pattern directly to video memory }π  For T:= 0 to 63999 do MEM[$A000:T]:=(T mod (317 + T div 10000)) and 255;ππ  Repeatπ   Vgabase(-1,-1);  { scroll smoothly in UPPER LEFT direction }π   Delay(14);π  Until KeyPressed;π  ch:=ReadKey;ππ  Repeatπ   Vgabase( 1, 1);  { scroll smoothly in LOWER RIGHT direction }π   Delay(14);π  Until KeyPressed;π  ch:=ReadKey;ππ  Asmπ  MOV AX,00003h   {reset to Textmode}π  inT 010hπ  end;ππend.π                                                                                                                            47     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VGASCRL3.PAS             IMPORT              23          {πI also wanted to put a picture bigger than the screen to scroll overπFor the intro.  --  ANIVGA  --π}ππProgram ScrollExample;π{Demonstrates how to use the VGA's hardware scroll to do some nice opening}π{sequence: the Program loads 3 Graphic pages With data and then scrolls   }π{them by. note that this erases the contents of the background page and   }π{thus shouldn't be used While animating sprites in parallel!}ππUsesπ  ANIVGA, Crt;ππProcedure IntroScroll(n,wait:Word);π{ in: n    = # rows to scroll up using hardware zoom}π{     wait = time (in ms) to wait after each row    }π{rem: Scrolling *always* starts at page 0 (=$A000:0000)   }π{     Thus, issuing "Screen(1-page)" afterwards is a must!}π{     if you put the routine into ANIVGA.PAS, you should delete all the}π{     Constants following this line}πConstπ  StartIndex=0;π  endIndex=StartIndex+3;π  {offsetadressen der Grafikseiten (in Segment $A000):}π  offset_Adr:Array[StartIndex..endIndex] of Word=($0000,$3E80,$7D00,$BB80);π  CrtAddress=$3D4; {if monochrome: $3B4}π  StatusReg =$3DA; {if monochrome: $3BA}πbeginπ  Screen(0);                  {position at $A000:0000}π  Asmπ    xor SI,SI                {use page address 0 }π    and SI,3π    SHL SI,1π    ADD SI,ofFSET offset_Adr-StartIndex*2 {call this "defensive Programming"..}π    LODSWπ    MOV BX,AXπ    MOV CX,nπ    MOV SI,waitπ  @oneline:π    ADD BX,LinESIZEπ    CLI                      {no inTs please!}π    MOV DX,StatusRegπ    @WaitnotHSyncLoop:π      in   al,dxπ      and  al,1π      jz  @WaitnotHSyncLoopπ    @WaitHSyncLoop:π      in   al,dxπ      and  al,1π      jz   @WaitHSyncLoopπ    MOV DX,CrtAddress        {Crt-controller}π    MOV AL,$0D               {LB-startaddress-register}π    OUT DX,ALπ    inC DXππ    MOV AL,BLπ    OUT DX,AL                {set new LB of starting address}π    DEC DXπ    MOV AL,$0Cπ    OUT DX,ALπ    inC DXπ    MOV AL,BH                {dto., HB}π    OUT DX,ALπ    STIππ    PUSH BXπ    PUSH CXπ    PUSH SIπ    PUSH SIπ    CALL Crt.Delayπ    POP SIπ    POP CXπ    POP BXπ    LOOP @onelineπ  end;πend;ππbeginπ InitGraph; {Program VGA into Graphic mode, clear all pages}ππ {--- Start of Intro ---}π Screen(0); {or SCROLLPAGE, just an aesthetic question...}π {Load 3 pages With pics, or draw them:}π LoadPage('1st.PIC',0);π LoadPage('2nd.PIC',1);π LoadPage('3rd.PIC',BackgndPage);π IntroScroll(3*200,20); {scroll up 3 pages, wait 20ms}π Delay(3000); {wait a few seconds}π Screen(1-page); {restore correct mode}π {--- end of Intro ---}ππ {now do your animations as usual}π {...}π CloseRoutines;πend.ππ{πif you adjust LoadPage() to allow loading into Graphic page 3 (=SCROLLPAGE),πtoo, you may easily do a 4 screen hardware scroll!π}π                                                                                                                             48     05-28-9313:39ALL                      SWAG SUPPORT TEAM        VIDSTUFF.PAS             IMPORT              43          {πKAI ROHRBACHERππ> explain MODE X.ππWell,  I don't care much about Mode X (which is 320x240x256), but use Mode Yπ(=320x200x256)  --at least I think that this mode is called "Mode Y" (as farπas  I  know, the terms were introduced by a series of Michael Abrash in "Dr.πDobb's  Journal" (?)). Nevertheless, things are identical With the exceptionπof initialising the VGA card! So here we go; note that the Asm code examplesπwere taken from my ANIVGA-toolkit: the PASCAL-equivalents when given are "onπthe  fly"  Asm->PASCAL  translations  For  improved  clarity (I hope...); inπdoubt, rely on the Asm part.ππMODE Y in a nutshellπ~~~~~~~~~~~~~~~~~~~~ππBasically,  Mode  Y  works  like  this:  use  the BIOS to switch into normalπ320x200x256  mode,  then reProgram the sequencer to unchain the 4 bitplanes.πThis  results  in  a bitplaned VRAM layout very similiar to the EGA/VGA's 16πcolor modes:π}πProcedure InitGraph; Assembler;πAsmπ  MOV AX,0013hπ  INT 10hπ  MOV DX,03C4hπ  MOV AL,04π  OUT DX,ALπ  INC DXπ  in  AL,DXπ  and AL,0F7hπ  or  AL,04π  OUT DX,ALπ  MOV DX,03C4hπ  MOV AL,02π  OUT DX,ALπ  INC DXπ  MOV AL,0Fhπ  OUT DX,ALπ  MOV AX,0A000hπ  MOV ES,AXπ  SUB DI,DIπ  MOV AX,DIπ  MOV CX,8000hπ  CLDπ  REP STOSWππ  MOV DX,CrtAddressπ  MOV AL,14hπ  OUT DX,ALπ  INC DXπ  in  AL,DXπ  and AL,0BFhπ  OUT DX,ALπ  DEC DXπ  MOV AL,17hπ  OUT DX,ALπ  INC DXπ  in  AL,DXπ  or  AL,40hπ  OUT DX,ALπend;ππ{πCrtAddress  and  StatusReg  are the port addresses For the VGA ports needed;πthey  are 3B4h and 3BAh on a monochrome display and 3D4h and 3DAh on a colorπdisplay, but can be determined at run-time, too:π}ππAsmπ  MOV DX,3CChπ  in AL,DXπ  TEST AL,1π  MOV DX,3D4hπ  JNZ @L1π  MOV DX,3B4hπ @L1:π  MOV CrtAddress,DXπ  ADD DX,6π  MOV StatusReg,DXπend;ππ{πThe  VRAM  layout  is  this:  underneath  each  memory  address in the rangeπ$A000:0000..$A000:$FFFF,  there  are  4 Bytes, each representing one pixel'sπcolor.πWhenever you Write to or read from such an address, an internal logic of theπVGA-card determines which one of those 4 pixels is accessed.πA  line  of  320  pixels (=320 Bytes) thus only takes 320/4=80 Bytes addressπspace,  but  to  address  a pixel, you need a) its VRAM address and b) whichπbitplane it's on.πThe  pixels  are arranged linearly: thus, the mapping from point coordinatesπto memory addresses is done by (x,y) <-> mem[$A000: y*80+ (x div 4)] and theπbitplane is determined by (x mod 4).π(Note coordinates start With 0 and that "div 4" can be computed very fast byπ"shr 2"; "mod 4" by "and 3").ππSo  you  computed the proper address and bitplane. If you want to _read_ theπpixel's color, you issue commands like this:π portw[$3CE]:=(bitplane SHL 8)+4; color:=mem[$A000:y*80+(x shr 2)]πOr For better speed & control, do it in Asm:ππ MOV AL,4π MOV AH,bitplaneπ MOV DX,3CEhπ CLIπ OUT DX,AXπ MOV AL,ES:[DI]π STIππ_Writing_  a pixel's color works similiar, but needs an additional step: theπmask is computed by 1 SHL bitplane (that is: 1/2/4/8 For mod4 values 0/1/2/3πrespectively):π portw[$3C4]:=(1 SHL bitplane+8)+2; mem[$A000:y*80+(x shr 2)]:=colorπOr using Asm again:ππ MOV CL,bitplaneπ MOV AH,1π SHL AH,CLπ MOV AL,2π MOV DX,3C4hπ CLIπ OUT DX,AXπ STOSBπ STIππAs  stated  above, one address represents 4 pixels, so 320x200 pixels occupyπ16000  address  Bytes.  We  do  have  65536  (=$A000:0..$A000:$FFFF) though,πtherefore  a  bit  more  than 4 pages are possible. It's up to you to defineπyour  pages,  0..15999=page  0,  16000..31999=page  1,  32000..47999=page 2,π48000..63999=page 3, 64000..65535=unused  is the most obvious layout.ππWhich  part  of  the VRAM is actually displayed can be Programmed by writingπthe  offset  part of the starting address to the Crt-controller (the segmentπpart is implicitly set to $A000):ππAsmπ  MOV DX,CrtAddressπ  MOV AL,$0Dπ  CLIπ  OUT DX,ALπ  INC DXπ  MOV AL,low Byte of starting offsetπ  OUT DX,ALπ  DEC DXπ  MOV AL,$0Cπ  OUT DX,ALπ  INC DXπ  MOV AL,high Byte of starting offsetπ  OUT DX,ALπ  STIπend;ππN.B.: if you reProgram the display's starting address more often than "everyπnow  and  then",  you  better  synchronize  that  to the vertical retrace orπhorizontal  enable  signal  of  your VGA card; otherwise, an annoying screenπflicker will become visible during switching!ππFor  example,  if  you do a "FOR i:=1 to 100 do SetAddress(i*80)", this willπresult  in a blinding fast hardware scroll: With each iteration of the loop,πthe  display will start 80 address Bytes (=320 pixels = 1 row) later, givingπthe impression of the display scrolling upwards.ππNote  that  Mode  X/Y  do  not differ in any other respect than their memoryπlayouts  from  all  the  other  bitplaned VGA modes: palette handling is theπsame,  as  is usage of the VGA's Write modes! In (default) Write mode 0, youπcan access the VRAM by Bytes, Words or dWords. Write mode 1 is handy to copyπthe  contents  of  one  Graphic  page to another: you are restricted to Byteπaccesses, but each one will transfer 4 Bytes at once.πFor example, a sequence like the following...πportw[$3C4]:=$0f02; portw[$3CE]:=$4105;πmove(mem[$a000:0000],mem[$a000:$3e80],16000);πportw[$3CE]:=$4005π...enables  all 4 planes, switches to Write mode 1, copies the (64000 Bytes)πcontents  of  the  2nd Graphic page to the 1st one and then switches back toπWrite mode 0 again.π}